Skip to contentSkip to conversation

drivers/mmc: Move dereference after NULL test

PATCH New [email protected] 1 participant 1 message Dec 15, 2009 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 170/196 drivers/mmc: Move dereference after NULL test

From: Julia Lawall <[email protected]>

If the NULL test on mrq is needed, then the derefernce should be after the NULL test.

A simplified version of the semantic match that detects this problem is as follows (http://coccinelle.lip6.fr/):

// <smpl>
@match exists@
expression x, E;
identifier fld;
@@

* x->fld
... when != \(x = E\|&x\)
* x == NULL
// </smpl>

---

 drivers/mmc/host/s3cmci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/s3cmci.c renamed from drivers/mmc/host/s3cmci.c~drivers-mmc-move-dereference-after-null-test +2 -1
diff -puN drivers/mmc/host/s3cmci.c~drivers-mmc-move-dereference-after-null-test drivers/mmc/host/s3cmci.c
@@ -820,7 +820,7 @@ fail_request:
 static void finalize_request(struct s3cmci_host *host)
 {
 	struct mmc_request *mrq = host->mrq;
-	struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
+	struct mmc_command *cmd;
 	int debug_as_failure = 0;
 
 	if (host->complete_what != COMPLETION_FINALIZE)
@@ -828,6 +828,7 @@ static void finalize_request(struct s3cm
 
 	if (!mrq)
 		return;
+	cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd;
 
 	if (cmd->data && (cmd->error == 0) &&
 	    (cmd->data->error == 0)) {

_