Skip to contentSkip to conversation

mmc: toshsd: move dereference below check for NULL

PATCH Applied Dan Carpenter 2 participants 2 messages Nov 15, 2014 – Nov 19, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: toshsd: move dereference below check for NULL

We check for NULL pointers after dereferencing so it's too late. Oddly enough, Smatch misses this code but complains about the caller passing NULL pointers to this function:

	drivers/mmc/host/toshsd.c:389 toshsd_irq()
	error: we previously assumed 'host->cmd' could be null (see line 349)
drivers/mmc/host/toshsd.c +2 -2
index edb06d6..4666262 100644
@@ -206,14 +206,14 @@ static irqreturn_t toshsd_thread_irq(int irq, void *dev_id)
 static void toshsd_cmd_irq(struct toshsd_host *host)
 {
 	struct mmc_command *cmd = host->cmd;
-	u8 *buf = (u8 *) cmd->resp;
+	u8 *buf;
 	u16 data;
 
 	if (!host->cmd) {
 		dev_warn(&host->pdev->dev, "Spurious CMD irq\n");
 		return;
 	}
-
+	buf = (u8 *)cmd->resp;
 	host->cmd = NULL;
 
 	if (cmd->flags & MMC_RSP_PRESENT && cmd->flags & MMC_RSP_136) {
Applied
#1 lore raw
Quoted 8 lines · Dan Carpenter

We check for NULL pointers after dereferencing so it's too late. Oddly enough, Smatch misses this code but complains about the caller passing NULL pointers to this function:

        drivers/mmc/host/toshsd.c:389 toshsd_irq()
        error: we previously assumed 'host->cmd' could be null (see line 349)

Thanks! Applied for next.

Kind regards
Uffe

Quoted 22 lines
drivers/mmc/host/toshsd.c +2 -2
index edb06d6..4666262 100644
@@ -206,14 +206,14 @@ static irqreturn_t toshsd_thread_irq(int irq, void *dev_id)
 static void toshsd_cmd_irq(struct toshsd_host *host)
 {
        struct mmc_command *cmd = host->cmd;
-       u8 *buf = (u8 *) cmd->resp;
+       u8 *buf;
        u16 data;
 
        if (!host->cmd) {
                dev_warn(&host->pdev->dev, "Spurious CMD irq\n");
                return;
        }
-
+       buf = (u8 *)cmd->resp;
        host->cmd = NULL;
 
        if (cmd->flags & MMC_RSP_PRESENT && cmd->flags & MMC_RSP_136) {