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: stable@vger.kernel.org
Signed-off-by: Nadezda Lutovinova <lutovinova@ispras.ru>
Link: https://lore.kernel.org/r/20210921155153.28098-3-lutovinova@ispras.ru
[groeck: Dropped unnecessary continuation lines, fixed multi-line alignments]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by Nadezda Lutovinova and committed by Guenter Roeck dd4d747e 0f36b881

+11 -15
+11 -15
drivers/hwmon/w83793.c
··· 202 } 203 204 struct w83793_data { 205 - struct i2c_client *lm75[2]; 206 struct device *hwmon_dev; 207 struct mutex update_lock; 208 char valid; /* !=0 if following fields are valid */ ··· 1565 int address = client->addr; 1566 u8 tmp; 1567 struct i2c_adapter *adapter = client->adapter; 1568 - struct w83793_data *data = i2c_get_clientdata(client); 1569 1570 id = i2c_adapter_id(adapter); 1571 if (force_subclients[0] == id && force_subclients[1] == address) { ··· 1584 } 1585 1586 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); 1587 - if (!(tmp & 0x08)) 1588 - data->lm75[0] = devm_i2c_new_dummy_device(&client->dev, adapter, 1589 - 0x48 + (tmp & 0x7)); 1590 - if (!(tmp & 0x80)) { 1591 - if (!IS_ERR(data->lm75[0]) 1592 - && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { 1593 - dev_err(&client->dev, 1594 - "duplicate addresses 0x%x, " 1595 - "use force_subclients\n", data->lm75[0]->addr); 1596 - return -ENODEV; 1597 - } 1598 - data->lm75[1] = devm_i2c_new_dummy_device(&client->dev, adapter, 1599 - 0x48 + ((tmp >> 4) & 0x7)); 1600 } 1601 1602 return 0; 1603 }
··· 202 } 203 204 struct w83793_data { 205 struct device *hwmon_dev; 206 struct mutex update_lock; 207 char valid; /* !=0 if following fields are valid */ ··· 1566 int address = client->addr; 1567 u8 tmp; 1568 struct i2c_adapter *adapter = client->adapter; 1569 1570 id = i2c_adapter_id(adapter); 1571 if (force_subclients[0] == id && force_subclients[1] == address) { ··· 1586 } 1587 1588 tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); 1589 + 1590 + if (!(tmp & 0x88) && (tmp & 0x7) == ((tmp >> 4) & 0x7)) { 1591 + dev_err(&client->dev, 1592 + "duplicate addresses 0x%x, use force_subclient\n", 0x48 + (tmp & 0x7)); 1593 + return -ENODEV; 1594 } 1595 + 1596 + if (!(tmp & 0x08)) 1597 + devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + (tmp & 0x7)); 1598 + 1599 + if (!(tmp & 0x80)) 1600 + devm_i2c_new_dummy_device(&client->dev, adapter, 0x48 + ((tmp >> 4) & 0x7)); 1601 1602 return 0; 1603 }