diff mbox series

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

Message ID 20180818020833.14376-1-jasonwood2031@gmail.com (mailing list archive)
State New, archived
Headers show
Series hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c() | expand

Commit Message

Jiecheng Wu Aug. 18, 2018, 2:08 a.m. UTC
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(-)

Comments

Himanshu Jha Aug. 18, 2018, 11:37 a.m. UTC | #1
[ + CC'ing relevant people ]

Hi Jiecheng,

On Sat, Aug 18, 2018 at 10:08:33AM +0800, Jiecheng Wu 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.

* Wrap up the commit log to 75 characters.
* Add your Signed-off-by: tag

All these warnings is stated by the checkpatch.
So, just run:

$ ./scripts/checkpatch.pl <your_patch>

Anothing question, did you actually hit this bug ? Or did you find doing
static analysis of code ?

Because I found your report on Bugzilla few days ago:
https://bugzilla.kernel.org/show_bug.cgi?id=200555#c0

Another exactly similar report before you reported.

These question shall determine whether the patch should be
backported to stable ?

I think yes, but I'll leave that upto maintainers.

Now, send the next version of patch to the relevant maintainers
using:

$ ./scripts/get_maintainer.pl <your_patch>

Adding Bugzilla-id to the commit log is also the tradition to
be followed.

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

Is this required ?

Thanks
diff mbox series

Patch

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);
 }