summaryrefslogtreecommitdiffstats
path: root/drivers/iio/magnetometer/hmc5843_i2c.c
diff options
context:
space:
mode:
authorKangjie Lu <kjlu@umn.edu>2019-03-16 17:08:33 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2019-04-04 20:20:14 +0100
commit536cc27deade8f1ec3c1beefa60d5fbe0f6fcb28 (patch)
tree6d6532e79caa87ca9b69f9f15a8032ca222df5bb /drivers/iio/magnetometer/hmc5843_i2c.c
parenta816646f08ce18e8787d241e1dbda5cbc314e5ea (diff)
downloadlinux-536cc27deade8f1ec3c1beefa60d5fbe0f6fcb28.tar.bz2
iio: hmc5843: fix potential NULL pointer dereferences
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> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/magnetometer/hmc5843_i2c.c')
-rw-r--r--drivers/iio/magnetometer/hmc5843_i2c.c7
1 files changed, 6 insertions, 1 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);
}