Skip to content

Commit d86f3c9

Browse files
committed
hwmon: (pmbus) Improve initialization of 'currpage' and 'currphase'
The 'currpage' and 'currphase' variables in struct pmbus_data are used by the PMBus core to determine if the phase or page value has changed. Both are initialized with values which are never expected to be set in the code to ensure that the first page/phase write operation is actually performed. This is not well explained and occasionally causes confusion. Change the type of both variables to s16 and initialize with -1 to ensure that the initial value never matches a requested value, and clarify that this value means "unknown/unset". Cc: Alex Qiu <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 6e0498d commit d86f3c9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ struct pmbus_data {
109109
bool has_status_word; /* device uses STATUS_WORD register */
110110
int (*read_status)(struct i2c_client *client, int page);
111111

112-
u8 currpage;
113-
u8 currphase; /* current phase, 0xff for all */
112+
s16 currpage; /* current page, -1 for unknown/unset */
113+
s16 currphase; /* current phase, 0xff for all, -1 for unknown/unset */
114114
};
115115

116116
struct pmbus_debugfs_entry {
@@ -2529,8 +2529,8 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
25292529
if (pdata)
25302530
data->flags = pdata->flags;
25312531
data->info = info;
2532-
data->currpage = 0xff;
2533-
data->currphase = 0xfe;
2532+
data->currpage = -1;
2533+
data->currphase = -1;
25342534

25352535
ret = pmbus_init_common(client, data, info);
25362536
if (ret < 0)

0 commit comments

Comments
 (0)