sata: ahsata: Fix resource leak
authorYe Li <ye.li@nxp.com>
Sun, 3 May 2020 14:27:00 +0000 (22:27 +0800)
committerTom Rini <trini@konsulko.com>
Fri, 8 May 2020 22:29:00 +0000 (18:29 -0400)
Fix coverity issue CID 3606684: Resource leak (RESOURCE_LEAK)
leaked_storage: Variable uc_priv going out of scope leaks the storage it points to

Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/ata/dwc_ahsata.c

index c2e28fe518eb4074247f82d4fa931e3886080a4f..a77521479280c1534ca0fc667b05ba69f714c63d 100644 (file)
@@ -847,6 +847,9 @@ static int ahci_init_one(int pdev)
        struct ahci_uc_priv *uc_priv = NULL;
 
        uc_priv = malloc(sizeof(struct ahci_uc_priv));
+       if (!uc_priv)
+               return -ENOMEM;
+
        memset(uc_priv, 0, sizeof(struct ahci_uc_priv));
        uc_priv->dev = pdev;
 
@@ -871,6 +874,8 @@ static int ahci_init_one(int pdev)
        return 0;
 
 err_out:
+       if (uc_priv)
+               free(uc_priv);
        return rc;
 }