Skip to content

Commit 943c15a

Browse files
Nadezda Lutovinovagroeck
authored andcommitted
hwmon: (w83791d) 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 multi-line alignment] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 2292e2f commit 943c15a

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

drivers/hwmon/w83791d.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ struct w83791d_data {
273273
char valid; /* !=0 if following fields are valid */
274274
unsigned long last_updated; /* In jiffies */
275275

276-
/* array of 2 pointers to subclients */
277-
struct i2c_client *lm75[2];
278-
279276
/* volts */
280277
u8 in[NUMBER_OF_VIN]; /* Register value */
281278
u8 in_max[NUMBER_OF_VIN]; /* Register value */
@@ -1257,7 +1254,6 @@ static const struct attribute_group w83791d_group_fanpwm45 = {
12571254
static int w83791d_detect_subclients(struct i2c_client *client)
12581255
{
12591256
struct i2c_adapter *adapter = client->adapter;
1260-
struct w83791d_data *data = i2c_get_clientdata(client);
12611257
int address = client->addr;
12621258
int i, id;
12631259
u8 val;
@@ -1280,22 +1276,19 @@ static int w83791d_detect_subclients(struct i2c_client *client)
12801276
}
12811277

12821278
val = w83791d_read(client, W83791D_REG_I2C_SUBADDR);
1283-
if (!(val & 0x08))
1284-
data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter,
1285-
0x48 + (val & 0x7));
1286-
if (!(val & 0x80)) {
1287-
if (!IS_ERR(data->lm75[0]) &&
1288-
((val & 0x7) == ((val >> 4) & 0x7))) {
1289-
dev_err(&client->dev,
1290-
"duplicate addresses 0x%x, "
1291-
"use force_subclient\n",
1292-
data->lm75[0]->addr);
1293-
return -ENODEV;
1294-
}
1295-
data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter,
1296-
0x48 + ((val >> 4) & 0x7));
1279+
1280+
if (!(val & 0x88) && (val & 0x7) == ((val >> 4) & 0x7)) {
1281+
dev_err(&client->dev,
1282+
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (val & 0x7));
1283+
return -ENODEV;
12971284
}
12981285

1286+
if (!(val & 0x08))
1287+
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (val & 0x7));
1288+
1289+
if (!(val & 0x80))
1290+
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((val >> 4) & 0x7));
1291+
12991292
return 0;
13001293
}
13011294

0 commit comments

Comments
 (0)