]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mmc: Take cleanup path to free memory on error exit
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Thu, 3 Jul 2025 14:03:30 +0000 (15:03 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 17 Jul 2025 17:39:06 +0000 (11:39 -0600)
Instead of returning -EINVAL directly which will not call the cleanup
path to free memory, fix the code to set the error and then goto the
cleanup code.

This issue found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/mmc/mmc.c

index 2c1f4f9c336bfed6c075a7bc47f373e8f8effa86..5f2efbe6df90a0c79f4db26afd846fddd9c548c0 100644 (file)
@@ -2365,8 +2365,10 @@ static int mmc_startup_v4(struct mmc *mmc)
                return -ENOMEM;
        memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN);
 #endif
-       if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions))
-               return -EINVAL;
+       if (ext_csd[EXT_CSD_REV] >= ARRAY_SIZE(mmc_versions)) {
+               err = -EINVAL;
+               goto error;
+       }
 
        mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]];