[PATCH 6/10] drivers/scsi: Move a dereference below a NULL test

From: Julia Lawall
Date: Sun Jul 19 2009 - 11:27:36 EST


From: Julia Lawall <julia@xxxxxxx>

If the NULL test is necessary, then the dereference should be moved below
the NULL test. I have additionally added a return if the NULL tests
succeeds, because it is not clear that the rest of the function, which is
for debugging only, makes sense in this case.

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

// <smpl>
@@
type T;
expression E,E1;
identifier i,fld;
statement S;
@@

- T i = E->fld;
+ T i;
... when != E=E1
when != i
if (E == NULL||...) S
+ i = E->fld;
// </smpl>

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

---
drivers/scsi/fd_mcs.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/scsi/fd_mcs.c b/drivers/scsi/fd_mcs.c
index 85bd54c..eff35cf 100644
--- a/drivers/scsi/fd_mcs.c
+++ b/drivers/scsi/fd_mcs.c
@@ -1127,11 +1127,13 @@ static void fd_mcs_print_info(Scsi_Cmnd * SCpnt)
unsigned int imr;
unsigned int irr;
unsigned int isr;
- struct Scsi_Host *shpnt = SCpnt->host;
+ struct Scsi_Host *shpnt;

if (!SCpnt || !SCpnt->host) {
printk("fd_mcs: cannot provide detailed information\n");
+ return;
}
+ shpnt = SCpnt->host;

printk("%s\n", fd_mcs_info(SCpnt->host));
print_banner(SCpnt->host);
--
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/