From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: <linux@armlinux.org.uk>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <robh@kernel.org>
Subject: Re: [PATCH] amba: fix refcount underflow if amba_device_add() fails
Date: Tue, 24 May 2022 11:15:44 +0800 [thread overview]
Message-ID: <c6ae7eda-0792-2ac0-e524-eb000366b50f@huawei.com> (raw)
In-Reply-To: <20220524030941.GA290608@roeck-us.net>
On 2022/5/24 11:09, Guenter Roeck wrote:
> On Tue, May 24, 2022 at 10:51:39AM +0800, Kefeng Wang wrote:
>> "ARM: 9192/1: amba: fix memory leak in amba_device_try_add()" leads
>> to a refcount underflow if amba_device_add() fails, which called by
>> of_amba_device_create(), the of_amba_device_create() already exists
>> the error handling, so amba_put_device() only need to be added into
>> amba_deferred_retry().
>>
>> Reported-by: Guenter Roeck <linux@roeck-us.net>
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> Tested-by: Guenter Roeck <linux@roeck-us.net>
Thanks.
PS: I also test with kmemleak, this could also fix previous memory leak
issue.
>
> Thanks,
> Guenter
>
>> ---
>> drivers/amba/bus.c | 8 ++------
>> 1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
>> index 0e3ed5eb367b..0cb20324da16 100644
>> --- a/drivers/amba/bus.c
>> +++ b/drivers/amba/bus.c
>> @@ -493,13 +493,8 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
>> goto skip_probe;
>>
>> ret = amba_read_periphid(dev);
>> - if (ret) {
>> - if (ret != -EPROBE_DEFER) {
>> - amba_device_put(dev);
>> - goto err_out;
>> - }
>> + if (ret)
>> goto err_release;
>> - }
>>
>> skip_probe:
>> ret = device_add(&dev->dev);
>> @@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
>> continue;
>>
>> list_del_init(&ddev->node);
>> + amba_device_put(ddev->dev);
>> kfree(ddev);
>> }
>>
>> --
>> 2.35.3
>>
> .
next prev parent reply other threads:[~2022-05-24 3:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 3:09 [PATCH] amba: fix refcount underflow if amba_device_add() fails Guenter Roeck
2022-05-24 3:15 ` Kefeng Wang [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-05-24 2:51 Kefeng Wang
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=c6ae7eda-0792-2ac0-e524-eb000366b50f@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=linux@roeck-us.net \
--cc=robh@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