Skip to contentSkip to conversation

iio: imu: mpu6050: fix possible NULL dereferences

PATCH In review Matt Ranostay 3 participants 4 messages Mar 3, 2016 – Mar 5, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: imu: mpu6050: fix possible NULL dereferences

Fix possible null dereferencing of i2c and spi driver data.

---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2 -1
index f581256d9d4c..d0c0e20c7122 100644
@@ -117,6 +117,7 @@ static int inv_mpu_probe(struct i2c_client *client,
 	struct inv_mpu6050_state *st;
 	int result;
 	const char *name = id ? id->name : NULL;
+	const int chip_type = id ? id->driver_data : 0;
 	struct regmap *regmap;
 
 	if (!i2c_check_functionality(client->adapter,
@@ -131,7 +132,7 @@ static int inv_mpu_probe(struct i2c_client *client,
 	}
 
 	result = inv_mpu_core_probe(regmap, client->irq, name,
-				    NULL, id->driver_data);
+				    NULL, chip_type);
 	if (result < 0)
 		return result;
 
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +2 -1
index dea6c4361de0..7bcb8d839f05 100644
@@ -46,6 +46,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 	struct regmap *regmap;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 	const char *name = id ? id->name : NULL;
+	const int chip_type = id ? id->driver_data : 0;
 
 	regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
 	if (IS_ERR(regmap)) {
@@ -55,7 +56,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 	}
 
 	return inv_mpu_core_probe(regmap, spi->irq, name,
-				  inv_mpu_i2c_disable, id->driver_data);
+				  inv_mpu_i2c_disable, chip_type);
 }
 
 static int inv_mpu_remove(struct spi_device *spi)
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 1 line · Matt Ranostay

Fix possible null dereferencing of i2c and spi driver data.

Is there actually a way of making this happen? Far as I know both i2c and spi should always provide an appropriate value... Is it the absence of a dt match table that is causing the issue?

Jonathan

Quoted 50 lines
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2 -1
index f581256d9d4c..d0c0e20c7122 100644
@@ -117,6 +117,7 @@ static int inv_mpu_probe(struct i2c_client *client,
 	struct inv_mpu6050_state *st;
 	int result;
 	const char *name = id ? id->name : NULL;
+	const int chip_type = id ? id->driver_data : 0;
 	struct regmap *regmap;
 
 	if (!i2c_check_functionality(client->adapter,
@@ -131,7 +132,7 @@ static int inv_mpu_probe(struct i2c_client *client,
 	}
 
 	result = inv_mpu_core_probe(regmap, client->irq, name,
-				    NULL, id->driver_data);
+				    NULL, chip_type);
 	if (result < 0)
 		return result;
 
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +2 -1
index dea6c4361de0..7bcb8d839f05 100644
@@ -46,6 +46,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 	struct regmap *regmap;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 	const char *name = id ? id->name : NULL;
+	const int chip_type = id ? id->driver_data : 0;
 
 	regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
 	if (IS_ERR(regmap)) {
@@ -55,7 +56,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 	}
 
 	return inv_mpu_core_probe(regmap, spi->irq, name,
-				  inv_mpu_i2c_disable, id->driver_data);
+				  inv_mpu_i2c_disable, chip_type);
 }
 
 static int inv_mpu_remove(struct spi_device *spi)
#2 lore raw
Quoted 6 lines · Jonathan Cameron
Quoted 1 line · Matt Ranostay

Fix possible null dereferencing of i2c and spi driver data.

Is there actually a way of making this happen? Far as I know both i2c and spi should always provide an appropriate value... Is it the absence of a dt match table that is causing the issue?

The original issue was a static checker warning of inconsistent NULL checks. I don't know if it can actually be NULL.

regards,
dan carpenter

maintainer
#3 lore raw
In reply to Matt Ranostay
Quoted 3 lines · Matt Ranostay

Fix possible null dereferencing of i2c and spi driver data.

Changed my mind and applied this as is rather than leaving it hanging. If it really makes no sense we can clear it out at a later date, along with the other case.

Quoted 48 lines
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c | 3 ++-
 drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c +2 -1
index f581256d9d4c..d0c0e20c7122 100644
@@ -117,6 +117,7 @@ static int inv_mpu_probe(struct i2c_client *client,
 	struct inv_mpu6050_state *st;
 	int result;
 	const char *name = id ? id->name : NULL;
+	const int chip_type = id ? id->driver_data : 0;
 	struct regmap *regmap;
 
 	if (!i2c_check_functionality(client->adapter,
@@ -131,7 +132,7 @@ static int inv_mpu_probe(struct i2c_client *client,
 	}
 
 	result = inv_mpu_core_probe(regmap, client->irq, name,
-				    NULL, id->driver_data);
+				    NULL, chip_type);
 	if (result < 0)
 		return result;
 
drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c +2 -1
index dea6c4361de0..7bcb8d839f05 100644
@@ -46,6 +46,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 	struct regmap *regmap;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 	const char *name = id ? id->name : NULL;
+	const int chip_type = id ? id->driver_data : 0;
 
 	regmap = devm_regmap_init_spi(spi, &inv_mpu_regmap_config);
 	if (IS_ERR(regmap)) {
@@ -55,7 +56,7 @@ static int inv_mpu_probe(struct spi_device *spi)
 	}
 
 	return inv_mpu_core_probe(regmap, spi->irq, name,
-				  inv_mpu_i2c_disable, id->driver_data);
+				  inv_mpu_i2c_disable, chip_type);
 }
 
 static int inv_mpu_remove(struct spi_device *spi)