linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: hmc: fix a potential NULL pointer dereference
@ 2019-03-09  5:15 Kangjie Lu
  2019-03-09 13:42 ` Tomasz Duszynski
  0 siblings, 1 reply; 7+ messages in thread
From: Kangjie Lu @ 2019-03-09  5:15 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

devm_regmap_init_i2c may fail and return NULL. The fix returns
the error when it fails.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
index 3de7f4426ac4..c0cd0823f8d5 100644
--- a/drivers/iio/magnetometer/hmc5843_i2c.c
+++ b/drivers/iio/magnetometer/hmc5843_i2c.c
@@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
 static int hmc5843_i2c_probe(struct i2c_client *cli,
 			     const struct i2c_device_id *id)
 {
+	struct regmap *devm_regmap = devm_regmap_init_i2c(cli,
+			&hmc5843_i2c_regmap_config);
+	if (IS_ERR(devm_regmap))
+		return PTR_ERR(devm_regmap);
+
 	return hmc5843_common_probe(&cli->dev,
-			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
+			devm_regmap,
 			id->driver_data, id->name);
 }
 
-- 
2.17.1


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

* Re: [PATCH] iio: hmc: fix a potential NULL pointer dereference
  2019-03-09  5:15 [PATCH] iio: hmc: fix a potential NULL pointer dereference Kangjie Lu
@ 2019-03-09 13:42 ` Tomasz Duszynski
  2019-03-09 18:29   ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Tomasz Duszynski @ 2019-03-09 13:42 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Fri, Mar 08, 2019 at 11:15:32PM -0600, Kangjie Lu wrote:
> devm_regmap_init_i2c may fail and return NULL. The fix returns
> the error when it fails.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
> index 3de7f4426ac4..c0cd0823f8d5 100644
> --- a/drivers/iio/magnetometer/hmc5843_i2c.c
> +++ b/drivers/iio/magnetometer/hmc5843_i2c.c
> @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
>  static int hmc5843_i2c_probe(struct i2c_client *cli,
>  			     const struct i2c_device_id *id)
>  {
> +	struct regmap *devm_regmap = devm_regmap_init_i2c(cli,
> +			&hmc5843_i2c_regmap_config);
> +	if (IS_ERR(devm_regmap))
> +		return PTR_ERR(devm_regmap);

This fixes only one part of the problem leaving identical spi issue
behind. I guess this check should be part of *common_probe().

> +
>  	return hmc5843_common_probe(&cli->dev,
> -			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
> +			devm_regmap,
>  			id->driver_data, id->name);
>  }
>
> --
> 2.17.1
>

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

* Re: [PATCH] iio: hmc: fix a potential NULL pointer dereference
  2019-03-09 13:42 ` Tomasz Duszynski
@ 2019-03-09 18:29   ` Jonathan Cameron
       [not found]     ` <57617810-6F1A-41BF-889C-7A056423C360@umn.edu>
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2019-03-09 18:29 UTC (permalink / raw)
  To: Tomasz Duszynski
  Cc: Kangjie Lu, pakki001, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Sat, 9 Mar 2019 14:42:09 +0100
Tomasz Duszynski <tduszyns@gmail.com> wrote:

> On Fri, Mar 08, 2019 at 11:15:32PM -0600, Kangjie Lu wrote:
> > devm_regmap_init_i2c may fail and return NULL. The fix returns
> > the error when it fails.
> >
> > Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> > ---
> >  drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
> > index 3de7f4426ac4..c0cd0823f8d5 100644
> > --- a/drivers/iio/magnetometer/hmc5843_i2c.c
> > +++ b/drivers/iio/magnetometer/hmc5843_i2c.c
> > @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
> >  static int hmc5843_i2c_probe(struct i2c_client *cli,
> >  			     const struct i2c_device_id *id)
> >  {
> > +	struct regmap *devm_regmap = devm_regmap_init_i2c(cli,
> > +			&hmc5843_i2c_regmap_config);
> > +	if (IS_ERR(devm_regmap))
> > +		return PTR_ERR(devm_regmap);  
> 
> This fixes only one part of the problem leaving identical spi issue
> behind. I guess this check should be part of *common_probe().
It could be, but that somewhat hides the error checking.

I'd prefer to see it fixed like this, but in both here and the spi
file.  Both this and spi in one patch would be great!

Thanks,

Jonathan

> 
> > +
> >  	return hmc5843_common_probe(&cli->dev,
> > -			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
> > +			devm_regmap,
> >  			id->driver_data, id->name);
> >  }
> >
> > --
> > 2.17.1
> >  


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

* Re: [PATCH] iio: hmc: fix a potential NULL pointer dereference
       [not found]     ` <57617810-6F1A-41BF-889C-7A056423C360@umn.edu>
@ 2019-03-16 15:19       ` Jonathan Cameron
  2019-03-16 22:08         ` [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences Kangjie Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2019-03-16 15:19 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: Tomasz Duszynski, pakki001, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Tue, 12 Mar 2019 02:19:25 -0500
Kangjie Lu <kjlu@umn.edu> wrote:

> > On Mar 9, 2019, at 12:29 PM, Jonathan Cameron <jic23@kernel.org> wrote:
> > 
> > On Sat, 9 Mar 2019 14:42:09 +0100
> > Tomasz Duszynski <tduszyns@gmail.com <mailto:tduszyns@gmail.com>> wrote:
> >   
> >> On Fri, Mar 08, 2019 at 11:15:32PM -0600, Kangjie Lu wrote:  
> >>> devm_regmap_init_i2c may fail and return NULL. The fix returns
> >>> the error when it fails.
> >>> 
> >>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> >>> ---
> >>> drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
> >>> 1 file changed, 6 insertions(+), 1 deletion(-)
> >>> 
> >>> diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
> >>> index 3de7f4426ac4..c0cd0823f8d5 100644
> >>> --- a/drivers/iio/magnetometer/hmc5843_i2c.c
> >>> +++ b/drivers/iio/magnetometer/hmc5843_i2c.c
> >>> @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
> >>> static int hmc5843_i2c_probe(struct i2c_client *cli,
> >>> 			     const struct i2c_device_id *id)
> >>> {
> >>> +	struct regmap *devm_regmap = devm_regmap_init_i2c(cli,
> >>> +			&hmc5843_i2c_regmap_config);
> >>> +	if (IS_ERR(devm_regmap))
> >>> +		return PTR_ERR(devm_regmap);    
> >> 
> >> This fixes only one part of the problem leaving identical spi issue
> >> behind. I guess this check should be part of *common_probe().  
> > It could be, but that somewhat hides the error checking.
> > 
> > I'd prefer to see it fixed like this, but in both here and the spi
> > file.  Both this and spi in one patch would be great!  
> 
> I’ve submitted the patch for spi as well.
> 
Ah. I missed it because of inconsistent patch naming.
Anyhow, there were some minor suggestions for that patch so please
send a v2 with the two combined.

Thanks

Jonathan

> > 
> > Thanks,
> > 
> > Jonathan
> >   
> >>   
> >>> +
> >>> 	return hmc5843_common_probe(&cli->dev,
> >>> -			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
> >>> +			devm_regmap,
> >>> 			id->driver_data, id->name);
> >>> }
> >>> 
> >>> --
> >>> 2.17.1  
> 


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

* [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences
  2019-03-16 15:19       ` Jonathan Cameron
@ 2019-03-16 22:08         ` Kangjie Lu
  2019-03-24 10:48           ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Kangjie Lu @ 2019-03-16 22:08 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

devm_regmap_init_i2c may fail and return NULL. The fix returns
the error when it fails.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
V2: fix the two together
---
 drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
 drivers/iio/magnetometer/hmc5843_spi.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
index 3de7f4426ac4..86abba5827a2 100644
--- a/drivers/iio/magnetometer/hmc5843_i2c.c
+++ b/drivers/iio/magnetometer/hmc5843_i2c.c
@@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
 static int hmc5843_i2c_probe(struct i2c_client *cli,
 			     const struct i2c_device_id *id)
 {
+	struct regmap *regmap = devm_regmap_init_i2c(cli,
+			&hmc5843_i2c_regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
 	return hmc5843_common_probe(&cli->dev,
-			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
+			regmap,
 			id->driver_data, id->name);
 }
 
diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c
index 535f03a70d63..8355713651d4 100644
--- a/drivers/iio/magnetometer/hmc5843_spi.c
+++ b/drivers/iio/magnetometer/hmc5843_spi.c
@@ -58,6 +58,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
 static int hmc5843_spi_probe(struct spi_device *spi)
 {
 	int ret;
+	struct regmap *regmap;
 	const struct spi_device_id *id = spi_get_device_id(spi);
 
 	spi->mode = SPI_MODE_3;
@@ -67,8 +68,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
 	if (ret)
 		return ret;
 
+	regmap = devm_regmap_init(spi, &hmc5843_spi_regmap_config);
+	if (IS_ERR(regmap))
+		return PTR_ERR(devm_regmap);
+
 	return hmc5843_common_probe(&spi->dev,
-			devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
+			regmap,
 			id->driver_data, id->name);
 }
 
-- 
2.17.1


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

* Re: [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences
  2019-03-16 22:08         ` [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences Kangjie Lu
@ 2019-03-24 10:48           ` Jonathan Cameron
  2019-03-24 11:50             ` Jonathan Cameron
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2019-03-24 10:48 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Sat, 16 Mar 2019 17:08:33 -0500
Kangjie Lu <kjlu@umn.edu> wrote:

> devm_regmap_init_i2c may fail and return NULL. The fix returns
> the error when it fails.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
Thanks.

Jonathan

> ---
> V2: fix the two together
> ---
>  drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
>  drivers/iio/magnetometer/hmc5843_spi.c | 7 ++++++-
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
> index 3de7f4426ac4..86abba5827a2 100644
> --- a/drivers/iio/magnetometer/hmc5843_i2c.c
> +++ b/drivers/iio/magnetometer/hmc5843_i2c.c
> @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
>  static int hmc5843_i2c_probe(struct i2c_client *cli,
>  			     const struct i2c_device_id *id)
>  {
> +	struct regmap *regmap = devm_regmap_init_i2c(cli,
> +			&hmc5843_i2c_regmap_config);
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(regmap);
> +
>  	return hmc5843_common_probe(&cli->dev,
> -			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
> +			regmap,
>  			id->driver_data, id->name);
>  }
>  
> diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c
> index 535f03a70d63..8355713651d4 100644
> --- a/drivers/iio/magnetometer/hmc5843_spi.c
> +++ b/drivers/iio/magnetometer/hmc5843_spi.c
> @@ -58,6 +58,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
>  static int hmc5843_spi_probe(struct spi_device *spi)
>  {
>  	int ret;
> +	struct regmap *regmap;
>  	const struct spi_device_id *id = spi_get_device_id(spi);
>  
>  	spi->mode = SPI_MODE_3;
> @@ -67,8 +68,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
>  	if (ret)
>  		return ret;
>  
> +	regmap = devm_regmap_init(spi, &hmc5843_spi_regmap_config);
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(devm_regmap);
> +
>  	return hmc5843_common_probe(&spi->dev,
> -			devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
> +			regmap,
>  			id->driver_data, id->name);
>  }
>  


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

* Re: [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences
  2019-03-24 10:48           ` Jonathan Cameron
@ 2019-03-24 11:50             ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2019-03-24 11:50 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler, linux-iio, linux-kernel

On Sun, 24 Mar 2019 10:48:56 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Sat, 16 Mar 2019 17:08:33 -0500
> Kangjie Lu <kjlu@umn.edu> wrote:
> 
> > devm_regmap_init_i2c may fail and return NULL. The fix returns
> > the error when it fails.
> > 
> > Signed-off-by: Kangjie Lu <kjlu@umn.edu>  
> Applied to the togreg branch of iio.git and pushed out as testing
> for the autobuilders to play with it.
> Thanks.

Ah, how the eye jumps over the obvious...

Good thing this one was caught by build tests.

See below.

I've fixed up in the tree.

Jonathan

> 
> Jonathan
> 
> > ---
> > V2: fix the two together
> > ---
> >  drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++-
> >  drivers/iio/magnetometer/hmc5843_spi.c | 7 ++++++-
> >  2 files changed, 12 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
> > index 3de7f4426ac4..86abba5827a2 100644
> > --- a/drivers/iio/magnetometer/hmc5843_i2c.c
> > +++ b/drivers/iio/magnetometer/hmc5843_i2c.c
> > @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
> >  static int hmc5843_i2c_probe(struct i2c_client *cli,
> >  			     const struct i2c_device_id *id)
> >  {
> > +	struct regmap *regmap = devm_regmap_init_i2c(cli,
> > +			&hmc5843_i2c_regmap_config);
> > +	if (IS_ERR(regmap))
> > +		return PTR_ERR(regmap);
> > +
> >  	return hmc5843_common_probe(&cli->dev,
> > -			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
> > +			regmap,
> >  			id->driver_data, id->name);
> >  }
> >  
> > diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c
> > index 535f03a70d63..8355713651d4 100644
> > --- a/drivers/iio/magnetometer/hmc5843_spi.c
> > +++ b/drivers/iio/magnetometer/hmc5843_spi.c
> > @@ -58,6 +58,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
> >  static int hmc5843_spi_probe(struct spi_device *spi)
> >  {
> >  	int ret;
> > +	struct regmap *regmap;
> >  	const struct spi_device_id *id = spi_get_device_id(spi);
> >  
> >  	spi->mode = SPI_MODE_3;
> > @@ -67,8 +68,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
> >  	if (ret)
> >  		return ret;
> >  
> > +	regmap = devm_regmap_init(spi, &hmc5843_spi_regmap_config);

devm_regmap_init_spi


> > +	if (IS_ERR(regmap))
> > +		return PTR_ERR(devm_regmap);

It's called regmap.

> > +
> >  	return hmc5843_common_probe(&spi->dev,
> > -			devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
> > +			regmap,
> >  			id->driver_data, id->name);
> >  }
> >    
> 


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

end of thread, other threads:[~2019-03-24 11:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-09  5:15 [PATCH] iio: hmc: fix a potential NULL pointer dereference Kangjie Lu
2019-03-09 13:42 ` Tomasz Duszynski
2019-03-09 18:29   ` Jonathan Cameron
     [not found]     ` <57617810-6F1A-41BF-889C-7A056423C360@umn.edu>
2019-03-16 15:19       ` Jonathan Cameron
2019-03-16 22:08         ` [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences Kangjie Lu
2019-03-24 10:48           ` Jonathan Cameron
2019-03-24 11:50             ` 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).