From: Dan Carpenter <dan.carpenter@linaro.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>,
Linus Walleij <linus.walleij@linaro.org>,
Chen Wang <unicorn_wang@outlook.com>,
Inochi Amaoto <inochiama@outlook.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org, error27@gmail.com
Subject: Re: [PATCH] pinctrl: sophgo: fix double free in cv1800_pctrl_dt_node_to_map()
Date: Thu, 10 Oct 2024 21:33:14 +0300 [thread overview]
Message-ID: <aac19faa-fd95-4c6a-9a41-e4f03f8e1733@stanley.mountain> (raw)
In-Reply-To: <41acfc55-9741-4cef-9254-f9e4be4da956@wanadoo.fr>
On Thu, Oct 10, 2024 at 07:17:19PM +0200, Christophe JAILLET wrote:
> Le 10/10/2024 à 13:18, Harshit Mogalapalli a écrit :
> > 'map' is allocated using devm_* which takes care of freeing the allocated
> > data, but in error paths there is a call to pinctrl_utils_free_map()
> > which also does kfree(map) which leads to a double free.
> >
> > Use kcalloc() instead of devm_kcalloc() as freeing is manually handled.
> >
> > Fixes: a29d8e93e710 ("pinctrl: sophgo: add support for CV1800B SoC")
> > Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
> > ---
> > This is based on static analysis with smatch, only compile tested.
> > ---
> > drivers/pinctrl/sophgo/pinctrl-cv18xx.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/pinctrl/sophgo/pinctrl-cv18xx.c b/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
> > index d18fc5aa84f7..57f2674e75d6 100644
> > --- a/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
> > +++ b/drivers/pinctrl/sophgo/pinctrl-cv18xx.c
> > @@ -221,7 +221,7 @@ static int cv1800_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
> > if (!grpnames)
> > return -ENOMEM;
> > - map = devm_kcalloc(dev, ngroups * 2, sizeof(*map), GFP_KERNEL);
> > + map = kcalloc(ngroups * 2, sizeof(*map), GFP_KERNEL);
> > if (!map)
> > return -ENOMEM;
>
> Hi,
>
> drivers/pinctrl/nuvoton/pinctrl-ma35.c seems to have the same issue.
>
Yep. That one is too complicated for Smatch to find. In this case, the kfree()
happened in the cleanup so it was in the same function.
regards,
dan carpenter
next prev parent reply other threads:[~2024-10-10 18:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 11:18 Harshit Mogalapalli
2024-10-10 17:17 ` Christophe JAILLET
2024-10-10 18:33 ` Dan Carpenter [this message]
2024-10-10 20:32 ` Christophe JAILLET
2024-10-10 19:11 ` Harshit Mogalapalli
2024-10-10 19:13 ` 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=aac19faa-fd95-4c6a-9a41-e4f03f8e1733@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=error27@gmail.com \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=inochiama@outlook.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=unicorn_wang@outlook.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®