Skip to content

Commit a41e19c

Browse files
sipragajic23
authored andcommitted
iio: adc: ina2xx: avoid NULL pointer dereference on OF device match
The affected lines were resulting in a NULL pointer dereference on our platform because the device tree contained the following list of compatible strings: power-sensor@40 { compatible = "ti,ina232", "ti,ina231"; ... }; Since the driver doesn't declare a compatible string "ti,ina232", the OF matching succeeds on "ti,ina231". But the I2C device ID info is populated via the first compatible string, cf. modalias population in of_i2c_get_board_info(). Since there is no "ina232" entry in the legacy I2C device ID table either, the struct i2c_device_id *id pointer in the probe function is NULL. Fix this by using the already populated type variable instead, which points to the proper driver data. Since the name is also wanted, add a generic one to the ina2xx_config table. Signed-off-by: Alvin Šipraga <[email protected]> Fixes: c43a102 ("iio: ina2xx: add support for TI INA2xx Power Monitors") Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 95fb1e7 commit a41e19c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/iio/adc/ina2xx-adc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static const struct regmap_config ina2xx_regmap_config = {
124124
enum ina2xx_ids { ina219, ina226 };
125125

126126
struct ina2xx_config {
127+
const char *name;
127128
u16 config_default;
128129
int calibration_value;
129130
int shunt_voltage_lsb; /* nV */
@@ -155,6 +156,7 @@ struct ina2xx_chip_info {
155156

156157
static const struct ina2xx_config ina2xx_config[] = {
157158
[ina219] = {
159+
.name = "ina219",
158160
.config_default = INA219_CONFIG_DEFAULT,
159161
.calibration_value = 4096,
160162
.shunt_voltage_lsb = 10000,
@@ -164,6 +166,7 @@ static const struct ina2xx_config ina2xx_config[] = {
164166
.chip_id = ina219,
165167
},
166168
[ina226] = {
169+
.name = "ina226",
167170
.config_default = INA226_CONFIG_DEFAULT,
168171
.calibration_value = 2048,
169172
.shunt_voltage_lsb = 2500,
@@ -996,7 +999,7 @@ static int ina2xx_probe(struct i2c_client *client)
996999
/* Patch the current config register with default. */
9971000
val = chip->config->config_default;
9981001

999-
if (id->driver_data == ina226) {
1002+
if (type == ina226) {
10001003
ina226_set_average(chip, INA226_DEFAULT_AVG, &val);
10011004
ina226_set_int_time_vbus(chip, INA226_DEFAULT_IT, &val);
10021005
ina226_set_int_time_vshunt(chip, INA226_DEFAULT_IT, &val);
@@ -1015,7 +1018,7 @@ static int ina2xx_probe(struct i2c_client *client)
10151018
}
10161019

10171020
indio_dev->modes = INDIO_DIRECT_MODE;
1018-
if (id->driver_data == ina226) {
1021+
if (type == ina226) {
10191022
indio_dev->channels = ina226_channels;
10201023
indio_dev->num_channels = ARRAY_SIZE(ina226_channels);
10211024
indio_dev->info = &ina226_info;
@@ -1024,7 +1027,7 @@ static int ina2xx_probe(struct i2c_client *client)
10241027
indio_dev->num_channels = ARRAY_SIZE(ina219_channels);
10251028
indio_dev->info = &ina219_info;
10261029
}
1027-
indio_dev->name = id->name;
1030+
indio_dev->name = id ? id->name : chip->config->name;
10281031

10291032
ret = devm_iio_kfifo_buffer_setup(&client->dev, indio_dev,
10301033
&ina2xx_setup_ops);

0 commit comments

Comments
 (0)