mmc: gen_atmel_mci: NULL check variable before use
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Tue, 29 Jul 2025 16:16:17 +0000 (17:16 +0100)
committerEugen Hristev <eugen.hristev@linaro.org>
Wed, 13 Aug 2025 09:59:36 +0000 (12:59 +0300)
In mci_send_cmd the pointer 'data' is optional so guard its use with a
NULL check to prevent any attempt to dereference it when not provided.

This issue was found by Smatch.

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

index 62aa6b3..838b4f4 100644 (file)
@@ -263,13 +263,15 @@ mci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
        /* Figure out the transfer arguments */
        cmdr = mci_encode_cmd(cmd, data, &error_flags);
 
-       mci_set_blklen(mci, data->blocksize);
+       if (data) {
+               mci_set_blklen(mci, data->blocksize);
 
-       /* For multi blocks read/write, set the block register */
-       if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK)
-                       || (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK))
-               writel(data->blocks | MMCI_BF(BLKLEN, data->blocksize),
-                      &mci->blkr);
+               /* For multi blocks read/write, set the block register */
+               if (cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK ||
+                   cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)
+                       writel(data->blocks | MMCI_BF(BLKLEN, data->blocksize),
+                              &mci->blkr);
+       }
 
        /* Send the command */
        writel(cmd->cmdarg, &mci->argr);