lkml.org 
[lkml]   [2019]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] iio: hmc: fix a potential NULL pointer dereference
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
>

\
 
 \ /
  Last update: 2019-03-09 14:43    [W:1.583 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site