Skip to contentSkip to conversation

hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c()

PATCH In review Jiecheng Wu 3 participants 3 messages Aug 19, 2018 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c()

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(-)
drivers/iio/magnetometer/hmc5843_i2c.c +8 -2
index 3de7f44..4911cf8 100644
@@ -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);
 }
 
Signature · 1 line
2.6.4
#1 lore raw
Quoted 5 lines · Jiecheng Wu

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.

Please take a careful look again at what points I suggested in a previous patch you sent.

Take a look at a sample patch:
https://lore.kernel.org/lkml/[email protected]/

* Signed-off-by:
* Bugzilla link:
* Send to relevant maintainers:

himanshu@himanshu-Vostro-3559:~/linux-next$ ./scripts/get_maintainer.pl ~/Downloads/hmc5843_i2c.c-fix-missing-return-value-check-of-devm_regmap_init_i2c.patch

Jonathan Cameron <[email protected]> (maintainer:IIO SUBSYSTEM AND DRIVERS) Hartmut Knaack <[email protected]> (reviewer:IIO SUBSYSTEM AND DRIVERS) Lars-Peter Clausen <[email protected]> (reviewer:IIO SUBSYSTEM AND DRIVERS) Peter Meerwald-Stadler <[email protected]> (reviewer:IIO SUBSYSTEM AND DRIVERS) [email protected] (open list:IIO SUBSYSTEM AND DRIVERS) [email protected] (open list)
* cc stable
* Fixes tag: -- would be helpful
* correct version numbering with changelog below the '---' (v1->v2->3 ...)

All these are documented here:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html

drivers/iio/magnetometer/hmc5843_i2c.c line 17

Quoted 13 lines
---
 drivers/iio/magnetometer/hmc5843_i2c.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/hmc5843_i2c.c +1 -0
index 3de7f44..4911cf8 100644
@@ -14,6 +14,7 @@
 #include <linux/regmap.h>
 #include <linux/iio/iio.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/device.h>

This include is not required since #include <linux/iio/iio.h> already includes it.

Signature · 4 lines
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology
#2 lore raw
In reply to Jiecheng Wu
Quoted 5 lines · On Sun, 19 Aug 2018 10:16:41 +0800 Jiecheng Wu <[email protected]> wrote:

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.

This text isn't accurate. Checking IS_ERR is definitely not checking against NULL.

+ the issue with missing signoff etc that has already been raised.

Jonathan

Quoted 32 lines
---
 drivers/iio/magnetometer/hmc5843_i2c.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/magnetometer/hmc5843_i2c.c +8 -2
index 3de7f44..4911cf8 100644
@@ -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);
 }