diff mbox series

iio: hmc: fix a potential NULL pointer dereference

Message ID 20190309051533.14309-1-kjlu@umn.edu (mailing list archive)
State New, archived
Headers show
Series iio: hmc: fix a potential NULL pointer dereference | expand

Commit Message

Kangjie Lu March 9, 2019, 5:15 a.m. UTC
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(-)

Comments

Tomasz Duszynski March 9, 2019, 1:42 p.m. UTC | #1
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
>
Jonathan Cameron March 9, 2019, 6:29 p.m. UTC | #2
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
> >
Jonathan Cameron March 16, 2019, 3:19 p.m. UTC | #3
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  
>
diff mbox series

Patch

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);
 }