[PATCH 2/2] mmc: gen_atmel_mci: NULL check variable before use
Andrew Goodbody
andrew.goodbody at linaro.org
Tue Jul 29 18:16:17 CEST 2025
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 at linaro.org>
---
drivers/mmc/gen_atmel_mci.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/mmc/gen_atmel_mci.c b/drivers/mmc/gen_atmel_mci.c
index 62aa6b3cb0b..838b4f4a65a 100644
--- a/drivers/mmc/gen_atmel_mci.c
+++ b/drivers/mmc/gen_atmel_mci.c
@@ -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);
--
2.39.5
More information about the U-Boot
mailing list