Commit 1444fbf2 authored by Dan Carpenter's avatar Dan Carpenter Committed by Mauro Carvalho Chehab

[media] staging: lirc: clean error handling in probe()

We have reorganized the error handling into a simpler and more canonical
format.
Additionally we removed extra empty lines, switched to devm_kzalloc(), and
substitute 'minor' by 'ret' in the igorplugusb_remote_probe() function.
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 51dd4d70
...@@ -240,10 +240,6 @@ static int unregister_from_lirc(struct igorplug *ir) ...@@ -240,10 +240,6 @@ static int unregister_from_lirc(struct igorplug *ir)
dprintk(DRIVER_NAME "[%d]: calling lirc_unregister_driver\n", devnum); dprintk(DRIVER_NAME "[%d]: calling lirc_unregister_driver\n", devnum);
lirc_unregister_driver(d->minor); lirc_unregister_driver(d->minor);
kfree(d);
ir->d = NULL;
kfree(ir);
return devnum; return devnum;
} }
...@@ -377,20 +373,16 @@ static int igorplugusb_remote_poll(void *data, struct lirc_buffer *buf) ...@@ -377,20 +373,16 @@ static int igorplugusb_remote_poll(void *data, struct lirc_buffer *buf)
return -ENODATA; return -ENODATA;
} }
static int igorplugusb_remote_probe(struct usb_interface *intf, static int igorplugusb_remote_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct usb_device *dev = NULL; struct usb_device *dev;
struct usb_host_interface *idesc = NULL; struct usb_host_interface *idesc = NULL;
struct usb_endpoint_descriptor *ep; struct usb_endpoint_descriptor *ep;
struct igorplug *ir = NULL; struct igorplug *ir = NULL;
struct lirc_driver *driver = NULL; struct lirc_driver *driver = NULL;
int devnum, pipe, maxp; int devnum, pipe, maxp;
int minor = 0;
char buf[63], name[128] = ""; char buf[63], name[128] = "";
int mem_failure = 0;
int ret; int ret;
dprintk(DRIVER_NAME ": usb probe called.\n"); dprintk(DRIVER_NAME ": usb probe called.\n");
...@@ -416,24 +408,18 @@ static int igorplugusb_remote_probe(struct usb_interface *intf, ...@@ -416,24 +408,18 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n", dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n",
devnum, CODE_LENGTH, maxp); devnum, CODE_LENGTH, maxp);
mem_failure = 0; ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
ir = kzalloc(sizeof(struct igorplug), GFP_KERNEL); if (!ir)
if (!ir) { return -ENOMEM;
mem_failure = 1;
goto mem_failure_switch; driver = devm_kzalloc(&intf->dev, sizeof(*driver), GFP_KERNEL);
} if (!driver)
driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); return -ENOMEM;
if (!driver) {
mem_failure = 2;
goto mem_failure_switch;
}
ir->buf_in = usb_alloc_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, ir->buf_in = usb_alloc_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN,
GFP_ATOMIC, &ir->dma_in); GFP_ATOMIC, &ir->dma_in);
if (!ir->buf_in) { if (!ir->buf_in)
mem_failure = 3; return -ENOMEM;
goto mem_failure_switch;
}
strcpy(driver->name, DRIVER_NAME " "); strcpy(driver->name, DRIVER_NAME " ");
driver->minor = -1; driver->minor = -1;
...@@ -449,27 +435,14 @@ static int igorplugusb_remote_probe(struct usb_interface *intf, ...@@ -449,27 +435,14 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
driver->dev = &intf->dev; driver->dev = &intf->dev;
driver->owner = THIS_MODULE; driver->owner = THIS_MODULE;
minor = lirc_register_driver(driver); ret = lirc_register_driver(driver);
if (minor < 0) if (ret < 0) {
mem_failure = 9;
mem_failure_switch:
switch (mem_failure) {
case 9:
usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN,
ir->buf_in, ir->dma_in); ir->buf_in, ir->dma_in);
case 3: return ret;
kfree(driver);
case 2:
kfree(ir);
case 1:
printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
devnum, mem_failure);
return -ENOMEM;
} }
driver->minor = minor; driver->minor = ret;
ir->d = driver; ir->d = driver;
ir->devnum = devnum; ir->devnum = devnum;
ir->usbdev = dev; ir->usbdev = dev;
...@@ -502,7 +475,6 @@ static int igorplugusb_remote_probe(struct usb_interface *intf, ...@@ -502,7 +475,6 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
return 0; return 0;
} }
static void igorplugusb_remote_disconnect(struct usb_interface *intf) static void igorplugusb_remote_disconnect(struct usb_interface *intf)
{ {
struct usb_device *usbdev = interface_to_usbdev(intf); struct usb_device *usbdev = interface_to_usbdev(intf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment