nand: free controller when no nand inserted or error
authorLiang Yang <liang.yang@amlogic.com>
Sun, 4 Feb 2018 13:34:39 +0000 (21:34 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Mon, 5 Mar 2018 07:34:26 +0000 (15:34 +0800)
PD#156734: nand : no nand or init error handle

Change-Id: I9a1383117db2021204826e04d36fb91ba4213126
Signed-off-by: Liang Yang <liang.yang@amlogic.com>
drivers/amlogic/mtd/m3_nand.c

index 3336a35..07367c6 100644 (file)
@@ -1070,7 +1070,7 @@ int nand_init(struct platform_device *pdev)
 {
        struct aml_nand_platform *plat = NULL;
        struct resource *res_mem, *res_irq;
-       int i, ret, size;
+       int i, ret = 0, size;
 
        controller = kzalloc(sizeof(struct hw_controller), GFP_KERNEL);
        if (controller == NULL)
@@ -1187,6 +1187,10 @@ int nand_init(struct platform_device *pdev)
                        continue;
                }
        }
+
+       if (ret)
+               kfree(controller);
+
        nand_curr_device = 1; /* fixit */
        return ret;
 }