From: Kefeng Wang <wangkefeng.wang@huawei.com> To: <linux@armlinux.org.uk>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org> Cc: <robh@kernel.org>, Kefeng Wang <wangkefeng.wang@huawei.com>, Guenter Roeck <linux@roeck-us.net> Subject: [PATCH] amba: fix refcount underflow if amba_device_add() fails Date: Tue, 24 May 2022 10:51:39 +0800 [thread overview] Message-ID: <20220524025139.40212-1-wangkefeng.wang@huawei.com> (raw) "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> --- 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
WARNING: multiple messages have this Message-ID (diff)
From: Kefeng Wang <wangkefeng.wang@huawei.com> To: <linux@armlinux.org.uk>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org> Cc: <robh@kernel.org>, Kefeng Wang <wangkefeng.wang@huawei.com>, Guenter Roeck <linux@roeck-us.net> Subject: [PATCH] amba: fix refcount underflow if amba_device_add() fails Date: Tue, 24 May 2022 10:51:39 +0800 [thread overview] Message-ID: <20220524025139.40212-1-wangkefeng.wang@huawei.com> (raw) "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> --- 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2022-05-24 2:41 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-24 2:51 Kefeng Wang [this message] 2022-05-24 2:51 ` [PATCH] amba: fix refcount underflow if amba_device_add() fails Kefeng Wang 2022-05-24 3:09 Guenter Roeck 2022-05-24 3:15 ` Kefeng Wang 2022-05-24 3:15 ` 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=20220524025139.40212-1-wangkefeng.wang@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: linkBe 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.