mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 7/7] drivers/usb/serial: Move a dereference below a NULL test
@ 2008-12-26  7:29 Julia Lawall
  2009-01-05 14:28 ` Alan Cox
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2008-12-26  7:29 UTC (permalink / raw)
  To: gregkh, linux-usb, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

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@diku.dk>

---
 drivers/usb/serial/usb-serial.c     |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 080ade2..45f8ce8 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -509,11 +509,11 @@ static void usb_serial_port_work(struct work_struct *work)
 		container_of(work, struct usb_serial_port, work);
 	struct tty_struct *tty;
 
-	dbg("%s - port %d", __func__, port->number);
-
 	if (!port)
 		return;
 
+	dbg("%s - port %d", __func__, port->number);
+
 	tty = tty_port_tty_get(&port->port);
 	if (!tty)
 		return;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 7/7] drivers/usb/serial: Move a dereference below a NULL test
  2008-12-26  7:29 [PATCH 7/7] drivers/usb/serial: Move a dereference below a NULL test Julia Lawall
@ 2009-01-05 14:28 ` Alan Cox
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Cox @ 2009-01-05 14:28 UTC (permalink / raw)
  To: Julia Lawall; +Cc: gregkh, linux-usb, linux-kernel, kernel-janitors

On Fri, 26 Dec 2008 08:29:19 +0100 (CET)
Julia Lawall <julia@diku.dk> wrote:

> From: Julia Lawall <julia@diku.dk>
> 
> If the NULL test is necessary, then the dereference should be moved below
> the NULL test.

Both serial ones reviewed and the NULL test removed entirely

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-05 14:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-26  7:29 [PATCH 7/7] drivers/usb/serial: Move a dereference below a NULL test Julia Lawall
2009-01-05 14:28 ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®