LF-3626: mtd: nand: gpmi: fix the explicit null dereference issue
authorHan Xu <han.xu@nxp.com>
Wed, 31 Mar 2021 19:47:55 +0000 (14:47 -0500)
committerHan Xu <han.xu@nxp.com>
Wed, 5 May 2021 03:25:52 +0000 (22:25 -0500)
A potiential null pointer dereference issue may occur in
gpmi_nfc_exec_op(), found by coverity, CID 9000785.

In the for loop, if loop continues in NAND_OP_CMD_INSTR case, the desc
pointer may leave as null, so move the pointer sanity check outside the
loop.

Signed-off-by: Han Xu <han.xu@nxp.com>
Reviewed-by: Frank Li <frank.li@nxp.com>
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c

index d7a157a..77b3592 100644 (file)
@@ -2598,11 +2598,11 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
                                                   &direct);
                        break;
                }
+       }
 
-               if (!desc) {
-                       ret = -ENXIO;
-                       goto unmap;
-               }
+       if (!desc) {
+               ret = -ENXIO;
+               goto unmap;
        }
 
        dev_dbg(this->dev, "%s setup done\n", __func__);