linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Kangjie Lu <kjlu@umn.edu>
Cc: pakki001@umn.edu, Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences
Date: Sun, 24 Mar 2019 10:48:56 +0000	[thread overview]
Message-ID: <20190324104856.3883150b@archlinux> (raw)
In-Reply-To: <20190316220836.25092-1-kjlu@umn.edu>

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


  reply	other threads:[~2019-03-24 10:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-03-24 11:50             ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190324104856.3883150b@archlinux \
    --to=jic23@kernel.org \
    --cc=kjlu@umn.edu \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pakki001@umn.edu \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).