From: Shawn Guo <shawnguo@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
Baoyou Xie <xie.baoyou@sanechips.com.cn>,
Xin Zhou <zhou.xin8@sanechips.com.cn>,
Jun Nie <jun.nie@linaro.org>,
linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Shawn Guo <shawn.guo@linaro.org>
Subject: [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()
Date: Sun, 16 Jul 2017 21:33:28 +0800 [thread overview]
Message-ID: <1500212008-29321-1-git-send-email-shawnguo@kernel.org> (raw)
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
next reply other threads:[~2017-07-16 13:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-16 13:33 Shawn Guo [this message]
2017-07-17 8:02 ` [PATCH] pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state() Dan Carpenter
2017-07-17 9:46 ` Shawn Guo
2017-07-17 9:55 ` Dan Carpenter
2017-08-02 8:31 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1500212008-29321-1-git-send-email-shawnguo@kernel.org \
--to=shawnguo@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=jun.nie@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=shawn.guo@linaro.org \
--cc=xie.baoyou@sanechips.com.cn \
--cc=zhou.xin8@sanechips.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).