Skip to content

Commit

Permalink
drivers/usb/class/usblp.c: adjust error handling code
Browse files Browse the repository at this point in the history
In this code, it is possible to tell statically whether usblp will be NULL
in the error handling code.

Oliver Neukum suggested to make a goto to the final return rather than 
return directly.

The semantic match that finds this problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
identifier f,err,l,l1;
type T;
expression x,E;
statement S;
@@

x = NULL
... when != goto l1;
* x = f(...)
... when != x
err = E;
goto l;
...
* if (x != NULL)
  S
return err;
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: Pete Zaitcev <zaitcev@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Julia Lawall authored and Greg Kroah-Hartman committed Oct 17, 2008
1 parent 5b775f6 commit 49b707b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions drivers/usb/class/usblp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,15 +1076,16 @@ static int usblp_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *dev = interface_to_usbdev (intf);
struct usblp *usblp = NULL;
struct usblp *usblp;
int protocol;
int retval;

/* Malloc and start initializing usblp structure so we can use it
* directly. */
if (!(usblp = kzalloc(sizeof(struct usblp), GFP_KERNEL))) {
usblp = kzalloc(sizeof(struct usblp), GFP_KERNEL);
if (!usblp) {
retval = -ENOMEM;
goto abort;
goto abort_ret;
}
usblp->dev = dev;
mutex_init(&usblp->wmut);
Expand Down Expand Up @@ -1179,12 +1180,11 @@ static int usblp_probe(struct usb_interface *intf,
usb_set_intfdata (intf, NULL);
device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
abort:
if (usblp) {
kfree(usblp->readbuf);
kfree(usblp->statusbuf);
kfree(usblp->device_id_string);
kfree(usblp);
}
kfree(usblp->readbuf);
kfree(usblp->statusbuf);
kfree(usblp->device_id_string);
kfree(usblp);
abort_ret:
return retval;
}

Expand Down

0 comments on commit 49b707b

Please sign in to comment.