Skip to content

Commit 0f36b88

Browse files
Nadezda Lutovinovagroeck
authored andcommitted
hwmon: (w83792d) Fix NULL pointer dereference by removing unnecessary structure field
If driver read val value sufficient for (val & 0x08) && (!(val & 0x80)) && ((val & 0x7) == ((val >> 4) & 0x7)) from device then Null pointer dereference occurs. (It is possible if tmp = 0b0xyz1xyz, where same literals mean same numbers) Also lm75[] does not serve a purpose anymore after switching to devm_i2c_new_dummy_device() in w83791d_detect_subclients(). The patch fixes possible NULL pointer dereference by removing lm75[]. Found by Linux Driver Verification project (linuxtesting.org). Cc: [email protected] Signed-off-by: Nadezda Lutovinova <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: Dropped unnecessary continuation lines, fixed multipline alignment] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 943c15a commit 0f36b88

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

drivers/hwmon/w83792d.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,6 @@ struct w83792d_data {
264264
char valid; /* !=0 if following fields are valid */
265265
unsigned long last_updated; /* In jiffies */
266266

267-
/* array of 2 pointers to subclients */
268-
struct i2c_client *lm75[2];
269-
270267
u8 in[9]; /* Register value */
271268
u8 in_max[9]; /* Register value */
272269
u8 in_min[9]; /* Register value */
@@ -927,7 +924,6 @@ w83792d_detect_subclients(struct i2c_client *new_client)
927924
int address = new_client->addr;
928925
u8 val;
929926
struct i2c_adapter *adapter = new_client->adapter;
930-
struct w83792d_data *data = i2c_get_clientdata(new_client);
931927

932928
id = i2c_adapter_id(adapter);
933929
if (force_subclients[0] == id && force_subclients[1] == address) {
@@ -946,21 +942,19 @@ w83792d_detect_subclients(struct i2c_client *new_client)
946942
}
947943

948944
val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR);
949-
if (!(val & 0x08))
950-
data->lm75[0] = devm_i2c_new_dummy_device(&new_client->dev, adapter,
951-
0x48 + (val & 0x7));
952-
if (!(val & 0x80)) {
953-
if (!IS_ERR(data->lm75[0]) &&
954-
((val & 0x7) == ((val >> 4) & 0x7))) {
955-
dev_err(&new_client->dev,
956-
"duplicate addresses 0x%x, use force_subclient\n",
957-
data->lm75[0]->addr);
958-
return -ENODEV;
959-
}
960-
data->lm75[1] = devm_i2c_new_dummy_device(&new_client->dev, adapter,
961-
0x48 + ((val >> 4) & 0x7));
945+
946+
if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
947+
dev_err(&new_client->dev,
948+
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
949+
return -ENODEV;
962950
}
963951

952+
if (!(val & 0x08))
953+
devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + (val & 0x7));
954+
955+
if (!(val & 0x80))
956+
devm_i2c_new_dummy_device(&new_client->dev, adapter, 0x48 + ((val >> 4) & 0x7));
957+
964958
return 0;
965959
}
966960

0 commit comments

Comments
 (0)