From: Guenter Roeck <linux@roeck-us.net>
To: Kefeng Wang <wangkefeng.wang@huawei.com>
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: Mon, 23 May 2022 20:09:41 -0700 [thread overview]
Message-ID: <20220524030941.GA290608@roeck-us.net> (raw)
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,
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 reply other threads:[~2022-05-24 3:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 3:09 Guenter Roeck [this message]
2022-05-24 3:15 ` [PATCH] amba: fix refcount underflow if amba_device_add() fails Kefeng Wang
-- 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=20220524030941.GA290608@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=robh@kernel.org \
--cc=wangkefeng.wang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox