ARM: sa1111: fix put_device() before device_add() in error path
PATCH 1/1 ARM: sa1111: fix put_device() before device_add() in error path
When request_resource() fails, a jump is made to err_resource label which calls put_device() on &dev->res without adding it first.
Kept the err_resource label and moved put_device() to err_add label.
--- arch/arm/common/sa1111.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/common/sa1111.c +1 -1
@@ -779,8 +779,8 @@ sa1111_init_one_child(struct sa1111 *sachip, struct resource *parent, err_add:release_resource (&dev->res); - err_resource:put_device (&dev->dev); + err_resource: err_alloc:return ret; }
Signature · 1 line
2.43.2
Russell King (Oracle)
maintainerQuoted 3 lines · Alfredo Cruz
When
request_resource()fails, a jump is made toerr_resourcelabel which callsput_device()on&dev->reswithout adding it first.
Kept theerr_resourcelabel and movedput_device()toerr_addlabel.
You fail to explain why this is incorrect. I think this patch is incorrect. The reason is as follows:
"dev" is allocated.dev->dev is then initialised. This initialises the struct device, setting its initial refcount to '1'.
We then request the resource. If this fails, then the device needs to be released. As refcounting has been initialised, it is *not* appropriate to simply kfree() "dev". The correct action, as noted by the device_initialize() documentation is to call put_device() on it. This is what the code does.
I _do_ hope you haven't submitted other patches like this, because if you have, they could well also be wrong.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!