From: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
To: YueHaibing <yuehaibing@huawei.com>
Cc: linus.walleij@linaro.org, yamada.masahiro@socionext.com,
keescook@chromium.org, linux-kernel@vger.kernel.org,
linux-gpio@vger.kernel.org
Subject: Re: [PATCH] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state
Date: Wed, 1 Aug 2018 10:36:45 +0800 [thread overview]
Message-ID: <20180801103645.5df924b9@xhacker.debian> (raw)
In-Reply-To: <20180731142501.21888-1-yuehaibing@huawei.com>
Hi,
On Tue, 31 Jul 2018 22:25:01 +0800 YueHaibing wrote:
> fixes following Smatch static check warning:
>
> drivers/pinctrl/berlin/berlin.c:237 berlin_pinctrl_build_state()
> warn: passing devm_ allocated variable to kfree. 'pctrl->functions'
>
> As we will be calling krealloc() on pointer 'pctrl->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.
Good catch. Comments below.
>
> Fixes: 3de68d331c24 ("pinctrl: berlin: add the core pinctrl driver for Marvell Berlin SoCs")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> drivers/pinctrl/berlin/berlin.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c
> index d6d183e..db2afb2 100644
> --- a/drivers/pinctrl/berlin/berlin.c
> +++ b/drivers/pinctrl/berlin/berlin.c
> @@ -216,10 +216,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
> }
>
> /* we will reallocate later */
> - pctrl->functions = devm_kcalloc(&pdev->dev,
> - max_functions,
> - sizeof(*pctrl->functions),
> - GFP_KERNEL);
> + pctrl->functions = kcalloc(max_functions,
> + sizeof(*pctrl->functions), GFP_KERNEL);
> if (!pctrl->functions)
> return -ENOMEM;
>
> @@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
> function++;
> }
>
> - if (!found)
> + if (!found) {
> + kfree(function);
is it enough to just free one function? I think we need to free functions.
> return -EINVAL;
> + }
>
> if (!function->groups) {
> function->groups =
> @@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
> sizeof(char *),
> GFP_KERNEL);
>
> - if (!function->groups)
> + if (!function->groups) {
> + kfree(function);
ditto
> return -ENOMEM;
> + }
> }
>
> groups = function->groups;
WARNING: multiple messages have this Message-ID (diff)
From: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
To: YueHaibing <yuehaibing@huawei.com>
Cc: <linus.walleij@linaro.org>, <yamada.masahiro@socionext.com>,
<keescook@chromium.org>, <linux-kernel@vger.kernel.org>,
<linux-gpio@vger.kernel.org>
Subject: Re: [PATCH] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state
Date: Wed, 1 Aug 2018 10:36:45 +0800 [thread overview]
Message-ID: <20180801103645.5df924b9@xhacker.debian> (raw)
In-Reply-To: <20180731142501.21888-1-yuehaibing@huawei.com>
Hi,
On Tue, 31 Jul 2018 22:25:01 +0800 YueHaibing wrote:
> fixes following Smatch static check warning:
>
> drivers/pinctrl/berlin/berlin.c:237 berlin_pinctrl_build_state()
> warn: passing devm_ allocated variable to kfree. 'pctrl->functions'
>
> As we will be calling krealloc() on pointer 'pctrl->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.
Good catch. Comments below.
>
> Fixes: 3de68d331c24 ("pinctrl: berlin: add the core pinctrl driver for Marvell Berlin SoCs")
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
> drivers/pinctrl/berlin/berlin.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c
> index d6d183e..db2afb2 100644
> --- a/drivers/pinctrl/berlin/berlin.c
> +++ b/drivers/pinctrl/berlin/berlin.c
> @@ -216,10 +216,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
> }
>
> /* we will reallocate later */
> - pctrl->functions = devm_kcalloc(&pdev->dev,
> - max_functions,
> - sizeof(*pctrl->functions),
> - GFP_KERNEL);
> + pctrl->functions = kcalloc(max_functions,
> + sizeof(*pctrl->functions), GFP_KERNEL);
> if (!pctrl->functions)
> return -ENOMEM;
>
> @@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
> function++;
> }
>
> - if (!found)
> + if (!found) {
> + kfree(function);
is it enough to just free one function? I think we need to free functions.
> return -EINVAL;
> + }
>
> if (!function->groups) {
> function->groups =
> @@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
> sizeof(char *),
> GFP_KERNEL);
>
> - if (!function->groups)
> + if (!function->groups) {
> + kfree(function);
ditto
> return -ENOMEM;
> + }
> }
>
> groups = function->groups;
next prev parent reply other threads:[~2018-08-01 2:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-31 14:25 [PATCH] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state YueHaibing
2018-07-31 14:25 ` YueHaibing
2018-08-01 2:36 ` Jisheng Zhang [this message]
2018-08-01 2:36 ` Jisheng Zhang
2018-08-01 4:12 ` YueHaibing
2018-08-01 4:12 ` YueHaibing
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=20180801103645.5df924b9@xhacker.debian \
--to=jisheng.zhang@synaptics.com \
--cc=keescook@chromium.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yamada.masahiro@socionext.com \
--cc=yuehaibing@huawei.com \
/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 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.