Skip to content

Commit dd4d747

Browse files
Nadezda Lutovinovagroeck
authored andcommitted
hwmon: (w83793) Fix NULL pointer dereference by removing unnecessary structure field
If driver read tmp value sufficient for (tmp & 0x08) && (!(tmp & 0x80)) && ((tmp & 0x7) == ((tmp >> 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 alignments] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 0f36b88 commit dd4d747

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

drivers/hwmon/w83793.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ static inline s8 TEMP_TO_REG(long val, s8 min, s8 max)
202202
}
203203

204204
struct w83793_data {
205-
struct i2c_client *lm75[2];
206205
struct device *hwmon_dev;
207206
struct mutex update_lock;
208207
char valid; /* !=0 if following fields are valid */
@@ -1566,7 +1565,6 @@ w83793_detect_subclients(struct i2c_client *client)
15661565
int address = client->addr;
15671566
u8 tmp;
15681567
struct i2c_adapter *adapter = client->adapter;
1569-
struct w83793_data *data = i2c_get_clientdata(client);
15701568

15711569
id = i2c_adapter_id(adapter);
15721570
if (force_subclients[0] == id && force_subclients[1] == address) {
@@ -1586,21 +1584,19 @@ w83793_detect_subclients(struct i2c_client *client)
15861584
}
15871585

15881586
tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR);
1589-
if (!(tmp & 0x08))
1590-
data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter,
1591-
0x48 + (tmp & 0x7));
1592-
if (!(tmp & 0x80)) {
1593-
if (!IS_ERR(data->lm75[0])
1594-
&& ((tmp & 0x7) == ((tmp >> 4) & 0x7))) {
1595-
dev_err(&client->dev,
1596-
"duplicate addresses 0x%x, "
1597-
"use force_subclients\n", data->lm75[0]->addr);
1598-
return -ENODEV;
1599-
}
1600-
data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter,
1601-
0x48 + ((tmp >> 4) & 0x7));
1587+
1588+
if (!(tmp & 0x88) && (tmp & 0x7) == ((tmp >> 4) & 0x7)) {
1589+
dev_err(&client->dev,
1590+
"duplicate addresses 0x%x, use force_subclient\n", 0x48 + (tmp & 0x7));
1591+
return -ENODEV;
16021592
}
16031593

1594+
if (!(tmp & 0x08))
1595+
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (tmp & 0x7));
1596+
1597+
if (!(tmp & 0x80))
1598+
devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((tmp >> 4) & 0x7));
1599+
16041600
return 0;
16051601
}
16061602

0 commit comments

Comments
 (0)