All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] pinctrl: sunxi: Testing the wrong variable
@ 2016-11-18 11:35 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2016-11-18 11:35 UTC (permalink / raw)
  To: Linus Walleij, Maxime Ripard
  Cc: Chen-Yu Tsai, Hans-Christian Egtvedt, Rob Herring,
	Krzysztof Adamski, Laxman Dewangan, Hans de Goede, linux-gpio,
	kernel-janitors

Smatch complains that we dereference "map" before testing it for NULL
which is true.  We should be testing "*map" instead.  Also on the error
path, we should free *map and set it to NULL.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 2339d47..5b0acba 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -398,13 +398,14 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 	 * map array
 	 */
 	*map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL);
-	if (!map)
+	if (!*map)
 		return -ENOMEM;
 
 	return 0;
 
 err_free_map:
-	kfree(map);
+	kfree(*map);
+	*map = NULL;
 	return ret;
 }
 

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

* [patch] pinctrl: sunxi: Testing the wrong variable
@ 2016-11-18 11:35 ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2016-11-18 11:35 UTC (permalink / raw)
  To: Linus Walleij, Maxime Ripard
  Cc: Chen-Yu Tsai, Hans-Christian Egtvedt, Rob Herring,
	Krzysztof Adamski, Laxman Dewangan, Hans de Goede, linux-gpio,
	kernel-janitors

Smatch complains that we dereference "map" before testing it for NULL
which is true.  We should be testing "*map" instead.  Also on the error
path, we should free *map and set it to NULL.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 2339d47..5b0acba 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -398,13 +398,14 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 	 * map array
 	 */
 	*map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL);
-	if (!map)
+	if (!*map)
 		return -ENOMEM;
 
 	return 0;
 
 err_free_map:
-	kfree(map);
+	kfree(*map);
+	*map = NULL;
 	return ret;
 }
 

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

* Re: [patch] pinctrl: sunxi: Testing the wrong variable
  2016-11-18 11:35 ` Dan Carpenter
@ 2016-11-18 13:18   ` Maxime Ripard
  -1 siblings, 0 replies; 6+ messages in thread
From: Maxime Ripard @ 2016-11-18 13:18 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Chen-Yu Tsai, Hans-Christian Egtvedt, Rob Herring,
	Krzysztof Adamski, Laxman Dewangan, Hans de Goede, linux-gpio,
	kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

On Fri, Nov 18, 2016 at 02:35:57PM +0300, Dan Carpenter wrote:
> Smatch complains that we dereference "map" before testing it for NULL
> which is true.  We should be testing "*map" instead.  Also on the error
> path, we should free *map and set it to NULL.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [patch] pinctrl: sunxi: Testing the wrong variable
@ 2016-11-18 13:18   ` Maxime Ripard
  0 siblings, 0 replies; 6+ messages in thread
From: Maxime Ripard @ 2016-11-18 13:18 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Chen-Yu Tsai, Hans-Christian Egtvedt, Rob Herring,
	Krzysztof Adamski, Laxman Dewangan, Hans de Goede, linux-gpio,
	kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

On Fri, Nov 18, 2016 at 02:35:57PM +0300, Dan Carpenter wrote:
> Smatch complains that we dereference "map" before testing it for NULL
> which is true.  We should be testing "*map" instead.  Also on the error
> path, we should free *map and set it to NULL.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Thanks!
Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

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

* Re: [patch] pinctrl: sunxi: Testing the wrong variable
  2016-11-18 11:35 ` Dan Carpenter
@ 2016-11-22  8:56   ` Linus Walleij
  -1 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2016-11-22  8:56 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Maxime Ripard, Chen-Yu Tsai, Hans-Christian Egtvedt, Rob Herring,
	Krzysztof Adamski, Laxman Dewangan, Hans de Goede, linux-gpio,
	kernel-janitors

On Fri, Nov 18, 2016 at 12:35 PM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:

> Smatch complains that we dereference "map" before testing it for NULL
> which is true.  We should be testing "*map" instead.  Also on the error
> path, we should free *map and set it to NULL.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Patch applied with Maxime's ACK.

Yours,
Linus Walleij

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

* Re: [patch] pinctrl: sunxi: Testing the wrong variable
@ 2016-11-22  8:56   ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2016-11-22  8:56 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Maxime Ripard, Chen-Yu Tsai, Hans-Christian Egtvedt, Rob Herring,
	Krzysztof Adamski, Laxman Dewangan, Hans de Goede, linux-gpio,
	kernel-janitors

On Fri, Nov 18, 2016 at 12:35 PM, Dan Carpenter
<dan.carpenter@oracle.com> wrote:

> Smatch complains that we dereference "map" before testing it for NULL
> which is true.  We should be testing "*map" instead.  Also on the error
> path, we should free *map and set it to NULL.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Patch applied with Maxime's ACK.

Yours,
Linus Walleij

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

end of thread, other threads:[~2016-11-22  8:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-18 11:35 [patch] pinctrl: sunxi: Testing the wrong variable Dan Carpenter
2016-11-18 11:35 ` Dan Carpenter
2016-11-18 13:18 ` Maxime Ripard
2016-11-18 13:18   ` Maxime Ripard
2016-11-22  8:56 ` Linus Walleij
2016-11-22  8:56   ` Linus Walleij

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.