Index: usb-devel/drivers/usb/misc/rio500.c =================================================================== --- usb-devel.orig/drivers/usb/misc/rio500.c +++ usb-devel/drivers/usb/misc/rio500.c @@ -454,36 +454,35 @@ static int probe_rio(struct usb_interfac { struct usb_device *dev = interface_to_usbdev(intf); struct rio_usb_data *rio = &rio_instance; - int retval = -ENOMEM; - char *ibuf, *obuf; + int retval; + mutex_lock(&rio500_mutex); if (rio->present) { dev_info(&intf->dev, "Second USB Rio at address %d refused\n", dev->devnum); - return -EBUSY; + retval = -EBUSY; + goto err_present; } dev_info(&intf->dev, "USB Rio found at address %d\n", dev->devnum); + rio->present = 1; - obuf = kmalloc(OBUF_SIZE, GFP_KERNEL); - if (!obuf) { + retval = -ENOMEM; + rio->obuf = kmalloc(OBUF_SIZE, GFP_KERNEL); + if (!rio->obuf) { dev_err(&dev->dev, "probe_rio: Not enough memory for the output buffer\n"); goto err_obuf; } - dev_dbg(&intf->dev, "obuf address: %p\n", obuf); + dev_dbg(&intf->dev, "obuf address: %p\n", rio->obuf); - ibuf = kmalloc(IBUF_SIZE, GFP_KERNEL); - if (!ibuf) { + rio->ibuf = kmalloc(IBUF_SIZE, GFP_KERNEL); + if (!rio->ibuf) { dev_err(&dev->dev, "probe_rio: Not enough memory for the input buffer\n"); goto err_ibuf; } - dev_dbg(&intf->dev, "ibuf address: %p\n", ibuf); + dev_dbg(&intf->dev, "ibuf address: %p\n", rio->ibuf); - mutex_lock(&rio500_mutex); rio->rio_dev = dev; - rio->ibuf = ibuf; - rio->obuf = obuf; - rio->present = 1; mutex_unlock(&rio500_mutex); retval = usb_register_dev(intf, &usb_rio_class); @@ -498,11 +497,14 @@ static int probe_rio(struct usb_interfac err_register: mutex_lock(&rio500_mutex); - rio->present = 0; - mutex_unlock(&rio500_mutex); + rio->rio_dev = NULL; + kfree(rio->ibuf); err_ibuf: - kfree(obuf); + kfree(rio->obuf); err_obuf: + rio->present = 0; + err_present: + mutex_unlock(&rio500_mutex); return retval; }