Skip to content

Commit

Permalink
ARM: 9207/1: amba: fix refcount underflow if amba_device_add() fails
Browse files Browse the repository at this point in the history
"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().

Fixes: 7719a68 ("ARM: 9192/1: amba: fix memory leak in amba_device_try_add()")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
  • Loading branch information
Wang Kefeng authored and Russell King (Oracle) committed Jul 14, 2022
1 parent e5c46fd commit 8030aa3
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions drivers/amba/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -546,6 +541,7 @@ static int amba_deferred_retry(void)
continue;

list_del_init(&ddev->node);
amba_device_put(ddev->dev);
kfree(ddev);
}

Expand Down

0 comments on commit 8030aa3

Please sign in to comment.