USB: adutux: fix up error paths
Make sure to return -ENOMEM on all allocation failures and -EIO on a string-retrieval error (instead of returning -ENODEV for some such errors). Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
15a818f459
commit
e0e9052034
|
@ -657,17 +657,15 @@ static int adu_probe(struct usb_interface *interface,
|
||||||
struct adu_device *dev = NULL;
|
struct adu_device *dev = NULL;
|
||||||
struct usb_host_interface *iface_desc;
|
struct usb_host_interface *iface_desc;
|
||||||
struct usb_endpoint_descriptor *endpoint;
|
struct usb_endpoint_descriptor *endpoint;
|
||||||
int retval = -ENODEV;
|
int retval = -ENOMEM;
|
||||||
int in_end_size;
|
int in_end_size;
|
||||||
int out_end_size;
|
int out_end_size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* allocate memory for our device state and initialize it */
|
/* allocate memory for our device state and initialize it */
|
||||||
dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL);
|
dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL);
|
||||||
if (!dev) {
|
if (!dev)
|
||||||
retval = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex_init(&dev->mtx);
|
mutex_init(&dev->mtx);
|
||||||
spin_lock_init(&dev->buflock);
|
spin_lock_init(&dev->buflock);
|
||||||
|
@ -689,10 +687,12 @@ static int adu_probe(struct usb_interface *interface,
|
||||||
}
|
}
|
||||||
if (dev->interrupt_in_endpoint == NULL) {
|
if (dev->interrupt_in_endpoint == NULL) {
|
||||||
dev_err(&interface->dev, "interrupt in endpoint not found\n");
|
dev_err(&interface->dev, "interrupt in endpoint not found\n");
|
||||||
|
retval = -ENODEV;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (dev->interrupt_out_endpoint == NULL) {
|
if (dev->interrupt_out_endpoint == NULL) {
|
||||||
dev_err(&interface->dev, "interrupt out endpoint not found\n");
|
dev_err(&interface->dev, "interrupt out endpoint not found\n");
|
||||||
|
retval = -ENODEV;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,10 +700,8 @@ static int adu_probe(struct usb_interface *interface,
|
||||||
out_end_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
|
out_end_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
|
||||||
|
|
||||||
dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL);
|
dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL);
|
||||||
if (!dev->read_buffer_primary) {
|
if (!dev->read_buffer_primary)
|
||||||
retval = -ENOMEM;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
/* debug code prime the buffer */
|
/* debug code prime the buffer */
|
||||||
memset(dev->read_buffer_primary, 'a', in_end_size);
|
memset(dev->read_buffer_primary, 'a', in_end_size);
|
||||||
|
@ -712,10 +710,8 @@ static int adu_probe(struct usb_interface *interface,
|
||||||
memset(dev->read_buffer_primary + (3 * in_end_size), 'd', in_end_size);
|
memset(dev->read_buffer_primary + (3 * in_end_size), 'd', in_end_size);
|
||||||
|
|
||||||
dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL);
|
dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL);
|
||||||
if (!dev->read_buffer_secondary) {
|
if (!dev->read_buffer_secondary)
|
||||||
retval = -ENOMEM;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
/* debug code prime the buffer */
|
/* debug code prime the buffer */
|
||||||
memset(dev->read_buffer_secondary, 'e', in_end_size);
|
memset(dev->read_buffer_secondary, 'e', in_end_size);
|
||||||
|
@ -743,6 +739,7 @@ static int adu_probe(struct usb_interface *interface,
|
||||||
if (!usb_string(udev, udev->descriptor.iSerialNumber, dev->serial_number,
|
if (!usb_string(udev, udev->descriptor.iSerialNumber, dev->serial_number,
|
||||||
sizeof(dev->serial_number))) {
|
sizeof(dev->serial_number))) {
|
||||||
dev_err(&interface->dev, "Could not retrieve serial number\n");
|
dev_err(&interface->dev, "Could not retrieve serial number\n");
|
||||||
|
retval = -EIO;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
dev_dbg(&interface->dev,"serial_number=%s", dev->serial_number);
|
dev_dbg(&interface->dev,"serial_number=%s", dev->serial_number);
|
||||||
|
@ -765,8 +762,8 @@ static int adu_probe(struct usb_interface *interface,
|
||||||
dev_info(&interface->dev, "ADU%d %s now attached to /dev/usb/adutux%d\n",
|
dev_info(&interface->dev, "ADU%d %s now attached to /dev/usb/adutux%d\n",
|
||||||
le16_to_cpu(udev->descriptor.idProduct), dev->serial_number,
|
le16_to_cpu(udev->descriptor.idProduct), dev->serial_number,
|
||||||
(dev->minor - ADU_MINOR_BASE));
|
(dev->minor - ADU_MINOR_BASE));
|
||||||
exit:
|
|
||||||
return retval;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
adu_delete(dev);
|
adu_delete(dev);
|
||||||
|
|
Loading…
Reference in New Issue