]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mmc: owl_mmc: Do not dereference data before NULL check
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Thu, 31 Jul 2025 11:11:47 +0000 (12:11 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 28 Oct 2025 16:32:59 +0000 (10:32 -0600)
In owl_mmc_prepare_data there is a NULL check for the pointer data but
it happens after data has already been dereferenced. Refactor the code
so that the NULL check happens before any code dereferences data.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
drivers/mmc/owl_mmc.c

index bd4906f58e7460dae300c4f299820a95dc8951e0..c18807b1f498ad718dbb336dfbfdf75f6d042e2e 100644 (file)
@@ -135,19 +135,19 @@ static void owl_mmc_prepare_data(struct owl_mmc_priv *priv,
 
        setbits_le32(priv->reg_base + OWL_REG_SD_EN, OWL_SD_EN_BSEL);
 
-       writel(data->blocks, priv->reg_base + OWL_REG_SD_BLK_NUM);
-       writel(data->blocksize, priv->reg_base + OWL_REG_SD_BLK_SIZE);
-       total = data->blocksize * data->blocks;
-
-       if (total < 512)
-               writel(total, priv->reg_base + OWL_REG_SD_BUF_SIZE);
-       else
-               writel(512, priv->reg_base + OWL_REG_SD_BUF_SIZE);
-
        /* DMA STOP */
        writel(0x0, SD_DMA_CHANNEL(priv->dma_channel, 0) + DMA_START);
 
        if (data) {
+               writel(data->blocks, priv->reg_base + OWL_REG_SD_BLK_NUM);
+               writel(data->blocksize, priv->reg_base + OWL_REG_SD_BLK_SIZE);
+               total = data->blocksize * data->blocks;
+
+               if (total < 512)
+                       writel(total, priv->reg_base + OWL_REG_SD_BUF_SIZE);
+               else
+                       writel(512, priv->reg_base + OWL_REG_SD_BUF_SIZE);
+
                if (data->flags == MMC_DATA_READ) {
                        buf = (ulong) (data->dest);
                        owl_dma_config(priv, (ulong) priv->reg_base +