amba: fix refcount underflow if amba_device_add() fails
Guenter Roeck
Tested-byQuoted 8 lines · Kefeng Wang
"ARM: 9192/1: amba: fix memory leak in
amba_device_try_add()" leads to a refcount underflow ifamba_device_add()fails, which called byof_amba_device_create(), theof_amba_device_create()already exists the error handling, soamba_put_device()only need to be added intoamba_deferred_retry().Reported-by Guenter Roeck <[email protected]>Signed-off-by Kefeng Wang <[email protected]>
Tested-by Guenter Roeck <[email protected]>
Thanks,
Guenter
Quoted 34 lines
--- drivers/amba/bus.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/amba/bus.c +2
-6@@ -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); }Signature · 1 line
2.35.3
Quoted 10 lines · Guenter Roeck
Quoted 8 lines · Kefeng Wang
"ARM: 9192/1: amba: fix memory leak in
amba_device_try_add()" leads to a refcount underflow ifamba_device_add()fails, which called byof_amba_device_create(), theof_amba_device_create()already exists the error handling, soamba_put_device()only need to be added intoamba_deferred_retry().Reported-by Guenter Roeck <[email protected]>Signed-off-by Kefeng Wang <[email protected]>Tested-by Guenter Roeck <[email protected]>
Thanks.
PS: I also test with kmemleak, this could also fix previous memory leak issue.
Quoted 39 lines
Thanks,
GuenterQuoted 34 lines
--- drivers/amba/bus.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/amba/bus.c +2
-6@@ -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); }Signature · 1 line
2.35.3.