* [patch] [media] staging: lirc: clean error handling in probe()
@ 2013-06-26 7:53 Dan Carpenter
2013-06-26 8:00 ` Andy Shevchenko
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2013-06-26 7:53 UTC (permalink / raw)
To: Jarod Wilson
Cc: Mauro Carvalho Chehab, YAMANE Toshiaki, Andy Shevchenko,
linux-media
I have reorganized the error handling into a simpler and more canonical
format.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/staging/media/lirc/lirc_igorplugusb.c b/drivers/staging/media/lirc/lirc_igorplugusb.c
index 2faa391..4cf3933 100644
--- a/drivers/staging/media/lirc/lirc_igorplugusb.c
+++ b/drivers/staging/media/lirc/lirc_igorplugusb.c
@@ -390,7 +390,6 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
int devnum, pipe, maxp;
int minor = 0;
char buf[63], name[128] = "";
- int mem_failure = 0;
int ret;
dprintk(DRIVER_NAME ": usb probe called.\n");
@@ -416,24 +415,17 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n",
devnum, CODE_LENGTH, maxp);
- mem_failure = 0;
ir = kzalloc(sizeof(struct igorplug), GFP_KERNEL);
- if (!ir) {
- mem_failure = 1;
- goto mem_failure_switch;
- }
+ if (!ir)
+ return -ENOMEM;
driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
- if (!driver) {
- mem_failure = 2;
- goto mem_failure_switch;
- }
+ if (!driver)
+ goto err_free_ir;
ir->buf_in = usb_alloc_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN,
GFP_ATOMIC, &ir->dma_in);
- if (!ir->buf_in) {
- mem_failure = 3;
- goto mem_failure_switch;
- }
+ if (!ir->buf_in)
+ goto err_free_driver;
strcpy(driver->name, DRIVER_NAME " ");
driver->minor = -1;
@@ -451,23 +443,7 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
minor = lirc_register_driver(driver);
if (minor < 0)
- mem_failure = 9;
-
-mem_failure_switch:
-
- switch (mem_failure) {
- case 9:
- usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN,
- ir->buf_in, ir->dma_in);
- case 3:
- kfree(driver);
- case 2:
- kfree(ir);
- case 1:
- printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
- devnum, mem_failure);
- return -ENOMEM;
- }
+ goto err_free_usb;
driver->minor = minor;
ir->d = driver;
@@ -500,6 +476,16 @@ mem_failure_switch:
usb_set_intfdata(intf, ir);
return 0;
+
+err_free_usb:
+ usb_free_coherent(dev, DEVICE_BUFLEN + DEVICE_HEADERLEN, ir->buf_in,
+ ir->dma_in);
+err_free_driver:
+ kfree(driver);
+err_free_ir:
+ kfree(ir);
+
+ return -ENOMEM;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch] [media] staging: lirc: clean error handling in probe()
2013-06-26 7:53 [patch] [media] staging: lirc: clean error handling in probe() Dan Carpenter
@ 2013-06-26 8:00 ` Andy Shevchenko
2013-06-26 10:37 ` Dan Carpenter
0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2013-06-26 8:00 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jarod Wilson, Mauro Carvalho Chehab, YAMANE Toshiaki, linux-media
On Wed, 2013-06-26 at 10:53 +0300, Dan Carpenter wrote:
> I have reorganized the error handling into a simpler and more canonical
> format.
Since you reorganize error handling, might be worth to convert it to
devm_*?
If you want I could do the patch.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] [media] staging: lirc: clean error handling in probe()
2013-06-26 8:00 ` Andy Shevchenko
@ 2013-06-26 10:37 ` Dan Carpenter
0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2013-06-26 10:37 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jarod Wilson, Mauro Carvalho Chehab, YAMANE Toshiaki, linux-media
On Wed, Jun 26, 2013 at 11:00:40AM +0300, Andy Shevchenko wrote:
> On Wed, 2013-06-26 at 10:53 +0300, Dan Carpenter wrote:
> > I have reorganized the error handling into a simpler and more canonical
> > format.
>
> Since you reorganize error handling, might be worth to convert it to
> devm_*?
>
> If you want I could do the patch.
Yeah. Using devm_kzalloc() would make it a lot simpler. That would
be great if you could re-write it that way. Thanks!
Please drop my patch in that case.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-06-26 10:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-26 7:53 [patch] [media] staging: lirc: clean error handling in probe() Dan Carpenter
2013-06-26 8:00 ` Andy Shevchenko
2013-06-26 10:37 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).