[PATCH 4/7] drivers/scsi: Move a dereference below a NULL test

From: Julia Lawall
Date: Fri Dec 26 2008 - 02:28:33 EST


From: Julia Lawall <julia@xxxxxxx>

If the NULL test is necessary, then the dereference should be moved below
the NULL test.

The semantic patch that makes this change is as follows:
(http://www.emn.fr/x-info/coccinelle/).

// <smpl>
@disable is_null@
identifier f;
expression E;
identifier fld;
statement S;
@@

+ if (E == NULL) S
f(...,E->fld,...);
- if (E == NULL) S

@@
identifier f;
expression E;
identifier fld;
statement S;
@@

+ if (!E) S
f(...,E->fld,...);
- if (!E) S
// </smpl>

Signed-off-by: Julia Lawall <julia@xxxxxxx>

---
drivers/scsi/eata_pio.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/eata_pio.c b/drivers/scsi/eata_pio.c
index 952505c..7fec87d 100644
--- a/drivers/scsi/eata_pio.c
+++ b/drivers/scsi/eata_pio.c
@@ -500,10 +500,11 @@ static int eata_pio_host_reset(struct scsi_cmnd *cmd)

sp = HD(cmd)->ccb[x].cmd;
HD(cmd)->ccb[x].status = RESET;
- printk(KERN_WARNING "eata_pio_reset: slot %d in reset, pid %ld.\n", x, sp->serial_number);
-
if (sp == NULL)
panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
+ printk(KERN_WARNING
+ "eata_pio_reset: slot %d in reset, pid %ld.\n",
+ x, sp->serial_number);
}

/* hard reset the HBA */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/