linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()
@ 2017-07-16 13:33 Shawn Guo
  2017-07-17  8:02 ` Dan Carpenter
  2017-08-02  8:31 ` Linus Walleij
  0 siblings, 2 replies; 5+ messages in thread
From: Shawn Guo @ 2017-07-16 13:33 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Dan Carpenter, Baoyou Xie, Xin Zhou, Jun Nie, linux-gpio,
	linux-arm-kernel, Shawn Guo

From: Shawn Guo <shawn.guo@linaro.org>

It fixes the following Smatch static check warning:

 drivers/pinctrl/zte/pinctrl-zx.c:338 zx_pinctrl_build_state()
 warn: passing devm_ allocated variable to kfree.

As we will be calling krealloc() on pointer 'functions', which means
kfree() will be called in there, devm_kzalloc() shouldn't be used with
the allocation in the first place.  Fix the warning by calling kcalloc()
and managing the free procedure in error path on our own.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: cbff0c4d27f4 ("pinctrl: add ZTE ZX pinctrl driver support")
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 drivers/pinctrl/zte/pinctrl-zx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/zte/pinctrl-zx.c b/drivers/pinctrl/zte/pinctrl-zx.c
index f828ee340a98..ded366bb6564 100644
--- a/drivers/pinctrl/zte/pinctrl-zx.c
+++ b/drivers/pinctrl/zte/pinctrl-zx.c
@@ -295,8 +295,7 @@ static int zx_pinctrl_build_state(struct platform_device *pdev)
 	pctldev->num_groups = ngroups;
 
 	/* Build function list from pin mux functions */
-	functions = devm_kzalloc(&pdev->dev, info->npins * sizeof(*functions),
-				 GFP_KERNEL);
+	functions = kcalloc(info->npins, sizeof(*functions), GFP_KERNEL);
 	if (!functions)
 		return -ENOMEM;
 
@@ -367,8 +366,10 @@ static int zx_pinctrl_build_state(struct platform_device *pdev)
 						func->num_group_names *
 						sizeof(*func->group_names),
 						GFP_KERNEL);
-				if (!func->group_names)
+				if (!func->group_names) {
+					kfree(functions);
 					return -ENOMEM;
+				}
 			}
 
 			group = func->group_names;
-- 
1.9.1


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

* Re: [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()
  2017-07-16 13:33 [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state() Shawn Guo
@ 2017-07-17  8:02 ` Dan Carpenter
  2017-07-17  9:46   ` Shawn Guo
  2017-08-02  8:31 ` Linus Walleij
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2017-07-17  8:02 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Linus Walleij, Baoyou Xie, linux-gpio, Xin Zhou, Jun Nie,
	Shawn Guo, linux-arm-kernel

Shouldn't there be a free if the remove function?  I'm not even sure
where the remove function is so I don't know.

regards,
dan carpenter

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

* Re: [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()
  2017-07-17  8:02 ` Dan Carpenter
@ 2017-07-17  9:46   ` Shawn Guo
  2017-07-17  9:55     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Shawn Guo @ 2017-07-17  9:46 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Linus Walleij, Baoyou Xie, Xin Zhou, Jun Nie, linux-gpio,
	linux-arm-kernel, Shawn Guo

On Mon, Jul 17, 2017 at 11:02:21AM +0300, Dan Carpenter wrote:
> Shouldn't there be a free if the remove function?  I'm not even sure
> where the remove function is so I don't know.

As the pinctrl driver is essential for the platform, it's always a
builtin_platform_driver which we do not even have a remove function.

Shawn

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

* Re: [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()
  2017-07-17  9:46   ` Shawn Guo
@ 2017-07-17  9:55     ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2017-07-17  9:55 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Linus Walleij, Baoyou Xie, linux-gpio, Xin Zhou, Jun Nie,
	Shawn Guo, linux-arm-kernel

On Mon, Jul 17, 2017 at 05:46:24PM +0800, Shawn Guo wrote:
> On Mon, Jul 17, 2017 at 11:02:21AM +0300, Dan Carpenter wrote:
> > Shouldn't there be a free if the remove function?  I'm not even sure
> > where the remove function is so I don't know.
> 
> As the pinctrl driver is essential for the platform, it's always a
> builtin_platform_driver which we do not even have a remove function.
> 

Ah.  Good deal, then.

regards,
dan carpenter

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

* Re: [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()
  2017-07-16 13:33 [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state() Shawn Guo
  2017-07-17  8:02 ` Dan Carpenter
@ 2017-08-02  8:31 ` Linus Walleij
  1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2017-08-02  8:31 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Dan Carpenter, Baoyou Xie, Xin Zhou, Jun Nie,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Shawn Guo

On Sun, Jul 16, 2017 at 3:33 PM, Shawn Guo <shawnguo@kernel.org> wrote:

> From: Shawn Guo <shawn.guo@linaro.org>
>
> It fixes the following Smatch static check warning:
>
>  drivers/pinctrl/zte/pinctrl-zx.c:338 zx_pinctrl_build_state()
>  warn: passing devm_ allocated variable to kfree.
>
> As we will be calling krealloc() on pointer 'functions', which means
> kfree() will be called in there, devm_kzalloc() shouldn't be used with
> the allocation in the first place.  Fix the warning by calling kcalloc()
> and managing the free procedure in error path on our own.
>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Fixes: cbff0c4d27f4 ("pinctrl: add ZTE ZX pinctrl driver support")
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>

Patch applied.

Yours,
Linus Walleij

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

end of thread, other threads:[~2017-08-02  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-16 13:33 [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state() Shawn Guo
2017-07-17  8:02 ` Dan Carpenter
2017-07-17  9:46   ` Shawn Guo
2017-07-17  9:55     ` Dan Carpenter
2017-08-02  8:31 ` Linus Walleij

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