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

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).