linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: mpu6050: fix possible NULL dereferences
@ 2016-03-03  3:18 Matt Ranostay
  2016-03-05 17:44 ` Jonathan Cameron
  2016-03-05 17:51 ` Jonathan Cameron
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Ranostay @ 2016-03-03  3:18 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, dan.carpenter, Matt Ranostay

Fix possible null dereferencing of i2c and spi driver data.

Signed-off-by: Matt Ranostay <matt.ranostay@intel.com>
---
 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(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
index f581256d9d4c..d0c0e20c7122 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
@@ -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;
 
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
index dea6c4361de0..7bcb8d839f05 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
@@ -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)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: mpu6050: fix possible NULL dereferences
  2016-03-03  3:18 [PATCH] iio: imu: mpu6050: fix possible NULL dereferences Matt Ranostay
@ 2016-03-05 17:44 ` Jonathan Cameron
  2016-03-05 17:49   ` Dan Carpenter
  2016-03-05 17:51 ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2016-03-05 17:44 UTC (permalink / raw)
  To: Matt Ranostay; +Cc: linux-iio, dan.carpenter

On 03/03/16 03:18, Matt Ranostay wrote:
> 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
> 
> Signed-off-by: Matt Ranostay <matt.ranostay@intel.com>
> ---
>  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(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index f581256d9d4c..d0c0e20c7122 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -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;
>  
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index dea6c4361de0..7bcb8d839f05 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -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)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: mpu6050: fix possible NULL dereferences
  2016-03-05 17:44 ` Jonathan Cameron
@ 2016-03-05 17:49   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2016-03-05 17:49 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Matt Ranostay, linux-iio

On Sat, Mar 05, 2016 at 05:44:24PM +0000, Jonathan Cameron wrote:
> On 03/03/16 03:18, Matt Ranostay wrote:
> > 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: imu: mpu6050: fix possible NULL dereferences
  2016-03-03  3:18 [PATCH] iio: imu: mpu6050: fix possible NULL dereferences Matt Ranostay
  2016-03-05 17:44 ` Jonathan Cameron
@ 2016-03-05 17:51 ` Jonathan Cameron
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2016-03-05 17:51 UTC (permalink / raw)
  To: Matt Ranostay; +Cc: linux-iio, dan.carpenter

On 03/03/16 03:18, Matt Ranostay wrote:
> Fix possible null dereferencing of i2c and spi driver data.
> 
> Signed-off-by: Matt Ranostay <matt.ranostay@intel.com>
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.
> ---
>  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(-)
> 
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> index f581256d9d4c..d0c0e20c7122 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_i2c.c
> @@ -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;
>  
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> index dea6c4361de0..7bcb8d839f05 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_spi.c
> @@ -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)
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-05 17:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-03  3:18 [PATCH] iio: imu: mpu6050: fix possible NULL dereferences Matt Ranostay
2016-03-05 17:44 ` Jonathan Cameron
2016-03-05 17:49   ` Dan Carpenter
2016-03-05 17:51 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).