From: "quanyang.wang" <quanyang.wang@windriver.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gpiolib: free device name on error path to fix kmemleak
Date: Sat, 30 Jan 2021 11:44:50 +0800 [thread overview]
Message-ID: <02e614e9-fe2f-d7b2-6c47-2431475780ed@windriver.com> (raw)
In-Reply-To: <CAHp75VemJWQDKFFrrCKWnUGHFiPhuh=4Aqhn8T6qF5yuMOCOKg@mail.gmail.com>
Hi Andy,
On 1/30/21 1:26 AM, Andy Shevchenko wrote:
> On Fri, Jan 29, 2021 at 2:01 PM <quanyang.wang@windriver.com> wrote:
>> From: Quanyang Wang <quanyang.wang@windriver.com>
>>
>> In gpiochip_add_data_with_key, we should check the return value of
>> dev_set_name to ensure that device name is allocated successfully
>> and then add a label on the error path to free device name to fix
>> kmemleak as below:
> Thanks for the report.
> Unfortunately...
>
>> + ret = dev_set_name(&gdev->dev, GPIOCHIP_NAME "%d", gdev->id);
>> + if (ret)
>> + goto err_free_ida;
> ...
>
>> +err_free_dev_name:
>> + kfree(dev_name(&gdev->dev));
> ...this approach seems to create a possible double free if I'm not mistaken.
Thanks for your comment. I didn't catch the double free. Would you
please point it out?
>
> The idea is that device name should be cleaned in kobject ->release()
> callback when device is put.
Yes, the device name should be freed by calling put_device(&gdev->dev).
But int gpiochip_add_data_with_key,
when running dev_set_name, "gdev->dev.release" hasn't been installed
until in the tail of gpiochip_add_data_with_key.
So we couldn't call put_device here.
Any suggestion is much appreciated.
Thanks,
Quanyang
> Can you elaborate?
>
next prev parent reply other threads:[~2021-01-30 9:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-29 8:19 [PATCH] gpiolib: free device name on error path to fix kmemleak quanyang.wang
2021-01-29 17:26 ` Andy Shevchenko
2021-01-30 3:44 ` quanyang.wang [this message]
2021-02-01 15:49 ` Bartosz Golaszewski
2021-02-01 17:36 ` Andy Shevchenko
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=02e614e9-fe2f-d7b2-6c47-2431475780ed@windriver.com \
--to=quanyang.wang@windriver.com \
--cc=andy.shevchenko@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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