diff options
author | Ulf Hansson <ulf.hansson@linaro.org> | 2015-06-01 14:57:09 +0200 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2015-09-11 15:51:35 +0200 |
commit | b7a41b23a718902cf9edb1346c3ded7d094cc9db (patch) | |
tree | c3473c548382f04cb5429cd4b84d8643678599eb | |
parent | aa528b5f63fa425c19f2ca3a578e07c4ee587e86 (diff) |
mmc: core: Put device and OF node at SDIO func removal in error pathwip_sdio_memleak
If the SDIO func device failed to be added via device_add(), the SDIO func
will be removed. In that error path, make sure to also decrease the
reference count for the device and OF node to prevent memory leakage.
ISSUE)
sdio_init_func() -> sdio_read_func_cis(), this do get_device(card) which is
reference is dropped in via sdio bus' ->release() callback. That's not safe,
since $subject patch may cause that path to be called without first having the
reference increased.
SOLUTION 1)
Increase reference of card for each sdio func that is allocated, instead of
tying it to the "tuple" allocation.
SOLUTION 2)
Don't decrease reference in the ->release callback, unless there are a tuple
allocated.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
-rw-r--r-- | drivers/mmc/core/sdio_bus.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c index 7e327a6dd53d..9f8a50401702 100644 --- a/drivers/mmc/core/sdio_bus.c +++ b/drivers/mmc/core/sdio_bus.c @@ -337,10 +337,9 @@ int sdio_add_func(struct sdio_func *func) */ void sdio_remove_func(struct sdio_func *func) { - if (!sdio_func_present(func)) - return; + if (sdio_func_present(func)) + device_del(&func->dev); - device_del(&func->dev); of_node_put(func->dev.of_node); put_device(&func->dev); } |