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

* Re: [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, 0 replies; 5+ messages in thread
From: Himanshu Jha @ 2018-08-18 11:37 UTC (permalink / raw)
  To: Jiecheng Wu; +Cc: linux-iio, jic23, atx, shubhrajyoti, pmeerw

[ + 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
-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

^ permalink raw reply	[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

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

On Sun, Aug 19, 2018 at 10:16:41AM +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.

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/20180531112107.13778-1-hdegoede@redhat.com/

* 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 <jic23@kernel.org> (maintainer:IIO SUBSYSTEM AND DRIVERS)
	Hartmut Knaack <knaack.h@gmx.de> (reviewer:IIO SUBSYSTEM AND DRIVERS)
	Lars-Peter Clausen <lars@metafoo.de> (reviewer:IIO SUBSYSTEM AND DRIVERS)
	Peter Meerwald-Stadler <pmeerw@pmeerw.net> (reviewer:IIO SUBSYSTEM AND DRIVERS)
	linux-iio@vger.kernel.org (open list:IIO SUBSYSTEM AND DRIVERS)
	linux-kernel@vger.kernel.org (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 | 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>

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

-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

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

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

On Sun, 19 Aug 2018 10:16:41 +0800
Jiecheng Wu <jasonwood2031@gmail.com> 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

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

^ permalink raw reply	[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-19  2:16 [PATCH] hmc5843_i2c.c: fix missing return value check of devm_regmap_init_i2c() Jiecheng Wu
2018-08-19  8:51 ` Himanshu Jha
2018-08-19 11:12 ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2018-08-18  2:08 Jiecheng Wu
2018-08-18 11:37 ` Himanshu Jha

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