* [PATCH v2] staging: lirc: clean error handling in probe()
@ 2013-06-26 14:37 Andy Shevchenko
2013-06-26 15:10 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2013-06-26 14:37 UTC (permalink / raw)
To: Dan Carpenter, Jarod Wilson, Mauro Carvalho Chehab,
YAMANE Toshiaki, linux-media
Cc: Andy Shevchenko
From: Dan Carpenter <dan.carpenter@oracle.com>
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: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/staging/media/lirc/lirc_igorplugusb.c | 56 +++++++--------------------
1 file changed, 14 insertions(+), 42 deletions(-)
diff --git a/drivers/staging/media/lirc/lirc_igorplugusb.c b/drivers/staging/media/lirc/lirc_igorplugusb.c
index 2faa391..28c8b0b 100644
--- a/drivers/staging/media/lirc/lirc_igorplugusb.c
+++ b/drivers/staging/media/lirc/lirc_igorplugusb.c
@@ -240,10 +240,6 @@ static int unregister_from_lirc(struct igorplug *ir)
dprintk(DRIVER_NAME "[%d]: calling lirc_unregister_driver\n", devnum);
lirc_unregister_driver(d->minor);
- kfree(d);
- ir->d = NULL;
- kfree(ir);
-
return devnum;
}
@@ -377,20 +373,16 @@ static int igorplugusb_remote_poll(void *data, struct lirc_buffer *buf)
return -ENODATA;
}
-
-
static int igorplugusb_remote_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
- struct usb_device *dev = NULL;
+ struct usb_device *dev;
struct usb_host_interface *idesc = NULL;
struct usb_endpoint_descriptor *ep;
struct igorplug *ir = NULL;
struct lirc_driver *driver = NULL;
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 +408,18 @@ 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;
- }
- driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
- if (!driver) {
- mem_failure = 2;
- goto mem_failure_switch;
- }
+ ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
+ if (!ir)
+ return -ENOMEM;
+
+ driver = devm_kzalloc(&intf->dev, sizeof(*driver), GFP_KERNEL);
+ if (!driver)
+ return -ENOMEM;
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)
+ return -ENOMEM;
strcpy(driver->name, DRIVER_NAME " ");
driver->minor = -1;
@@ -449,27 +435,14 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
driver->dev = &intf->dev;
driver->owner = THIS_MODULE;
- minor = lirc_register_driver(driver);
- if (minor < 0)
- mem_failure = 9;
-
-mem_failure_switch:
-
- switch (mem_failure) {
- case 9:
+ ret = lirc_register_driver(driver);
+ if (ret < 0) {
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;
+ return ret;
}
- driver->minor = minor;
+ driver->minor = ret;
ir->d = driver;
ir->devnum = devnum;
ir->usbdev = dev;
@@ -502,7 +475,6 @@ mem_failure_switch:
return 0;
}
-
static void igorplugusb_remote_disconnect(struct usb_interface *intf)
{
struct usb_device *usbdev = interface_to_usbdev(intf);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: lirc: clean error handling in probe()
2013-06-26 14:37 [PATCH v2] staging: lirc: clean error handling in probe() Andy Shevchenko
@ 2013-06-26 15:10 ` Dan Carpenter
2013-06-26 15:29 ` Andy Shevchenko
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2013-06-26 15:10 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jarod Wilson, Mauro Carvalho Chehab, YAMANE Toshiaki, linux-media
On Wed, Jun 26, 2013 at 05:37:36PM +0300, Andy Shevchenko wrote:
> From: Dan Carpenter <dan.carpenter@oracle.com>
>
> 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: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
I don't want credit for this, because I didn't do the work.
Signed-off-by is a legal thing like signing a document... But I
have reviewed it and it looks good.
Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: lirc: clean error handling in probe()
2013-06-26 15:10 ` Dan Carpenter
@ 2013-06-26 15:29 ` Andy Shevchenko
2013-06-26 15:58 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2013-06-26 15:29 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jarod Wilson, Mauro Carvalho Chehab, YAMANE Toshiaki, linux-media
On Wed, 2013-06-26 at 18:10 +0300, Dan Carpenter wrote:
> On Wed, Jun 26, 2013 at 05:37:36PM +0300, Andy Shevchenko wrote:
> > From: Dan Carpenter <dan.carpenter@oracle.com>
> >
> > 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: Dan Carpenter <dan.carpenter@oracle.com>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> I don't want credit for this, because I didn't do the work.
> Signed-off-by is a legal thing like signing a document...
I took your patch and modified it, so, you have done some work too.
But I could resend a version with my authorship.
> But I
> have reviewed it and it looks good.
>
> Acked-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> regards,
> dan carpenter
>
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] staging: lirc: clean error handling in probe()
2013-06-26 15:29 ` Andy Shevchenko
@ 2013-06-26 15:58 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2013-06-26 15:58 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jarod Wilson, Mauro Carvalho Chehab, YAMANE Toshiaki, linux-media
On Wed, Jun 26, 2013 at 06:29:12PM +0300, Andy Shevchenko wrote:
> On Wed, 2013-06-26 at 18:10 +0300, Dan Carpenter wrote:
> > On Wed, Jun 26, 2013 at 05:37:36PM +0300, Andy Shevchenko wrote:
> > > From: Dan Carpenter <dan.carpenter@oracle.com>
> > >
> > > 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: Dan Carpenter <dan.carpenter@oracle.com>
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > I don't want credit for this, because I didn't do the work.
> > Signed-off-by is a legal thing like signing a document...
>
> I took your patch and modified it, so, you have done some work too.
> But I could resend a version with my authorship.
I don't think any of my work survived the re-write, but I'm happy
enough to take credit for other people's work. :) Don't bother
resending.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-06-26 15:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-26 14:37 [PATCH v2] staging: lirc: clean error handling in probe() Andy Shevchenko
2013-06-26 15:10 ` Dan Carpenter
2013-06-26 15:29 ` Andy Shevchenko
2013-06-26 15:58 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox