Skip to content

Commit 3834a75

Browse files
Yuuoniystorulf
authored andcommitted
mmc: omap: Fix memory leak in mmc_omap_new_slot
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: e519f0b ("ARM/mmc: Convert old mmci-omap to GPIO descriptors") Signed-off-by: Miaoqian Lin <linmq006@gmail.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250318140226.19650-1-linmq006@gmail.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 4676741 commit 3834a75

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

drivers/mmc/host/omap.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,19 +1272,25 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
12721272
/* Check for some optional GPIO controls */
12731273
slot->vsd = devm_gpiod_get_index_optional(host->dev, "vsd",
12741274
id, GPIOD_OUT_LOW);
1275-
if (IS_ERR(slot->vsd))
1276-
return dev_err_probe(host->dev, PTR_ERR(slot->vsd),
1275+
if (IS_ERR(slot->vsd)) {
1276+
r = dev_err_probe(host->dev, PTR_ERR(slot->vsd),
12771277
"error looking up VSD GPIO\n");
1278+
goto err_free_host;
1279+
}
12781280
slot->vio = devm_gpiod_get_index_optional(host->dev, "vio",
12791281
id, GPIOD_OUT_LOW);
1280-
if (IS_ERR(slot->vio))
1281-
return dev_err_probe(host->dev, PTR_ERR(slot->vio),
1282+
if (IS_ERR(slot->vio)) {
1283+
r = dev_err_probe(host->dev, PTR_ERR(slot->vio),
12821284
"error looking up VIO GPIO\n");
1285+
goto err_free_host;
1286+
}
12831287
slot->cover = devm_gpiod_get_index_optional(host->dev, "cover",
12841288
id, GPIOD_IN);
1285-
if (IS_ERR(slot->cover))
1286-
return dev_err_probe(host->dev, PTR_ERR(slot->cover),
1289+
if (IS_ERR(slot->cover)) {
1290+
r = dev_err_probe(host->dev, PTR_ERR(slot->cover),
12871291
"error looking up cover switch GPIO\n");
1292+
goto err_free_host;
1293+
}
12881294

12891295
host->slots[id] = slot;
12901296

@@ -1344,6 +1350,7 @@ static int mmc_omap_new_slot(struct mmc_omap_host *host, int id)
13441350
device_remove_file(&mmc->class_dev, &dev_attr_slot_name);
13451351
err_remove_host:
13461352
mmc_remove_host(mmc);
1353+
err_free_host:
13471354
mmc_free_host(mmc);
13481355
return r;
13491356
}

0 commit comments

Comments
 (0)