mmc: bcm2835: fix potential null pointer dereferences
authorGustavo A. R. Silva <garsilva@embeddedor.com>
Thu, 25 May 2017 17:04:55 +0000 (12:04 -0500)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 20 Jun 2017 08:30:31 +0000 (10:30 +0200)
Null check at line 1165: if (mrq->cmd), implies that mrq->cmd might
be NULL.
Add null checks before dereferencing pointer mrq->cmd in order to avoid
any potential NULL pointer dereference.

Addresses-Coverity-ID: 1408740
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/bcm2835.c

index 1f343a477b3d3ab2f03a391cf956b6f2546847ef..abba9a2a78b87be991d397a8205c2adea152d178 100644 (file)
@@ -1172,7 +1172,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
        if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
                dev_err(dev, "unsupported block size (%d bytes)\n",
                        mrq->data->blksz);
-               mrq->cmd->error = -EINVAL;
+
+               if (mrq->cmd)
+                       mrq->cmd->error = -EINVAL;
+
                mmc_request_done(mmc, mrq);
                return;
        }
@@ -1194,7 +1197,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
                        readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK,
                        edm);
                bcm2835_dumpregs(host);
-               mrq->cmd->error = -EILSEQ;
+
+               if (mrq->cmd)
+                       mrq->cmd->error = -EILSEQ;
+
                bcm2835_finish_request(host);
                mutex_unlock(&host->mutex);
                return;
@@ -1207,7 +1213,7 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
                        if (!host->use_busy)
                                bcm2835_finish_command(host);
                }
-       } else if (bcm2835_send_command(host, mrq->cmd)) {
+       } else if (mrq->cmd && bcm2835_send_command(host, mrq->cmd)) {
                if (host->data && host->dma_desc) {
                        /* DMA transfer starts now, PIO starts after irq */
                        bcm2835_start_dma(host);