linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c()
@ 2018-08-18  2:08 Jiecheng Wu
  2018-08-18 11:37 ` Himanshu Jha
  0 siblings, 1 reply; 5+ messages in thread
From: Jiecheng Wu @ 2018-08-18  2:08 UTC (permalink / raw)
  To: linux-iio

Function hmc5843_i2c_probe() defined in drivers/iio/magnetometer/hmc5843_i2c.c calls devm_regmap_init_i2c() to initialise managed register map. As the return value of devm_regmap_init_i2c() will be an ERR_PTR() on error, the return value must be checked against NULL.
---
 drivers/iio/magnetometer/hmc5843_i2c.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
index 3de7f44..4911cf8 100644
--- a/drivers/iio/magnetometer/hmc5843_i2c.c
+++ b/drivers/iio/magnetometer/hmc5843_i2c.c
@@ -14,6 +14,7 @@
 #include <linux/regmap.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/device.h>
 
 #include "hmc5843.h"
 
@@ -58,8 +59,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)
 {
-	return hmc5843_common_probe(&cli->dev,
-			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
+	struct regmap *regmap;
+	regmap = devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config);
+	if (IS_ERR(regmap)) {
+		dev_err(&cli->dev, "Failed to initialize i2c regmap\n");
+		return PTR_ERR(regmap);
+	}
+	return hmc5843_common_probe(&cli->dev, regmap,
 			id->driver_data, id->name);
 }
 
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c()
@ 2018-08-19  2:16 Jiecheng Wu
  2018-08-19  8:51 ` Himanshu Jha
  2018-08-19 11:12 ` Jonathan Cameron
  0 siblings, 2 replies; 5+ messages in thread
From: Jiecheng Wu @ 2018-08-19  2:16 UTC (permalink / raw)
  To: linux-iio

Function hmc5843_i2c_probe() defined in
 drivers/iio/magnetometer/hmc5843_i2c.c calls devm_regmap_init_i2c()
 to initialise managed register map. As the return value of
 devm_regmap_init_i2c() will be an ERR_PTR() on error, the return
 value must be checked against NULL.
---
 drivers/iio/magnetometer/hmc5843_i2c.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
index 3de7f44..4911cf8 100644
--- a/drivers/iio/magnetometer/hmc5843_i2c.c
+++ b/drivers/iio/magnetometer/hmc5843_i2c.c
@@ -14,6 +14,7 @@
 #include <linux/regmap.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/device.h>
 
 #include "hmc5843.h"
 
@@ -58,8 +59,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)
 {
-	return hmc5843_common_probe(&cli->dev,
-			devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
+	struct regmap *regmap;
+	regmap = devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config);
+	if (IS_ERR(regmap)) {
+		dev_err(&cli->dev, "Failed to initialize i2c regmap\n");
+		return PTR_ERR(regmap);
+	}
+	return hmc5843_common_probe(&cli->dev, regmap,
 			id->driver_data, id->name);
 }
 
-- 
2.6.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-19 14:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-18  2:08 [PATCH] hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c() Jiecheng Wu
2018-08-18 11:37 ` Himanshu Jha
  -- strict thread matches above, loose matches on Subject: below --
2018-08-19  2:16 Jiecheng Wu
2018-08-19  8:51 ` Himanshu Jha
2018-08-19 11:12 ` 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).