* [PATCH] mmc: omap: Fix memory leak in mmc_omap_new_slot
@ 2025-03-18 14:02 Miaoqian Lin
2025-03-19 11:39 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2025-03-18 14:02 UTC (permalink / raw)
To: Aaro Koskinen, Ulf Hansson, Aubin Constans, Uwe Kleine-König,
Christian Loehle, Allen Pais, Linus Walleij, linux-omap,
linux-mmc, linux-kernel
Cc: linmq006
Add err_free_host label to properly pair mmc_alloc_host() with
mmc_free_host() in GPIO error paths. The allocated host memory was
leaked when GPIO lookups failed.
Fixes: e519f0bb64ef ("ARM/mmc: Convert old mmci-omap to GPIO descriptors")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/mmc/host/omap.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 62252ad4e20d..3cdb2fc44965 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1272,19 +1272,25 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
/* Check for some optional GPIO controls */
slot->vsd = devm_gpiod_get_index_optional(host->dev, "vsd",
id, GPIOD_OUT_LOW);
- if (IS_ERR(slot->vsd))
- return dev_err_probe(host->dev, PTR_ERR(slot->vsd),
+ if (IS_ERR(slot->vsd)) {
+ r = dev_err_probe(host->dev, PTR_ERR(slot->vsd),
"error looking up VSD GPIO\n");
+ goto err_free_host;
+ }
slot->vio = devm_gpiod_get_index_optional(host->dev, "vio",
id, GPIOD_OUT_LOW);
- if (IS_ERR(slot->vio))
- return dev_err_probe(host->dev, PTR_ERR(slot->vio),
+ if (IS_ERR(slot->vio)) {
+ r = dev_err_probe(host->dev, PTR_ERR(slot->vio),
"error looking up VIO GPIO\n");
+ goto err_free_host;
+ }
slot->cover = devm_gpiod_get_index_optional(host->dev, "cover",
id, GPIOD_IN);
- if (IS_ERR(slot->cover))
- return dev_err_probe(host->dev, PTR_ERR(slot->cover),
+ if (IS_ERR(slot->cover)) {
+ r = dev_err_probe(host->dev, PTR_ERR(slot->cover),
"error looking up cover switch GPIO\n");
+ goto err_free_host;
+ }
host->slots[id] = slot;
@@ -1344,6 +1350,7 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
device_remove_file(&mmc->class_dev, &dev_attr_slot_name);
err_remove_host:
mmc_remove_host(mmc);
+err_free_host:
mmc_free_host(mmc);
return r;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mmc: omap: Fix memory leak in mmc_omap_new_slot
2025-03-18 14:02 [PATCH] mmc: omap: Fix memory leak in mmc_omap_new_slot Miaoqian Lin
@ 2025-03-19 11:39 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2025-03-19 11:39 UTC (permalink / raw)
To: Miaoqian Lin
Cc: Aaro Koskinen, Aubin Constans, Uwe Kleine-König,
Christian Loehle, Allen Pais, Linus Walleij, linux-omap,
linux-mmc, linux-kernel
On Tue, 18 Mar 2025 at 15:02, Miaoqian Lin <linmq006@gmail.com> wrote:
>
> Add err_free_host label to properly pair mmc_alloc_host() with
> mmc_free_host() in GPIO error paths. The allocated host memory was
> leaked when GPIO lookups failed.
>
> Fixes: e519f0bb64ef ("ARM/mmc: Convert old mmci-omap to GPIO descriptors")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Applied for next and by adding a stable tag, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/host/omap.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
> index 62252ad4e20d..3cdb2fc44965 100644
> --- a/drivers/mmc/host/omap.c
> +++ b/drivers/mmc/host/omap.c
> @@ -1272,19 +1272,25 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
> /* Check for some optional GPIO controls */
> slot->vsd = devm_gpiod_get_index_optional(host->dev, "vsd",
> id, GPIOD_OUT_LOW);
> - if (IS_ERR(slot->vsd))
> - return dev_err_probe(host->dev, PTR_ERR(slot->vsd),
> + if (IS_ERR(slot->vsd)) {
> + r = dev_err_probe(host->dev, PTR_ERR(slot->vsd),
> "error looking up VSD GPIO\n");
> + goto err_free_host;
> + }
> slot->vio = devm_gpiod_get_index_optional(host->dev, "vio",
> id, GPIOD_OUT_LOW);
> - if (IS_ERR(slot->vio))
> - return dev_err_probe(host->dev, PTR_ERR(slot->vio),
> + if (IS_ERR(slot->vio)) {
> + r = dev_err_probe(host->dev, PTR_ERR(slot->vio),
> "error looking up VIO GPIO\n");
> + goto err_free_host;
> + }
> slot->cover = devm_gpiod_get_index_optional(host->dev, "cover",
> id, GPIOD_IN);
> - if (IS_ERR(slot->cover))
> - return dev_err_probe(host->dev, PTR_ERR(slot->cover),
> + if (IS_ERR(slot->cover)) {
> + r = dev_err_probe(host->dev, PTR_ERR(slot->cover),
> "error looking up cover switch GPIO\n");
> + goto err_free_host;
> + }
>
> host->slots[id] = slot;
>
> @@ -1344,6 +1350,7 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
> device_remove_file(&mmc->class_dev, &dev_attr_slot_name);
> err_remove_host:
> mmc_remove_host(mmc);
> +err_free_host:
> mmc_free_host(mmc);
> return r;
> }
> --
> 2.39.5 (Apple Git-154)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-19 11:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-18 14:02 [PATCH] mmc: omap: Fix memory leak in mmc_omap_new_slot Miaoqian Lin
2025-03-19 11:39 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox