* [PATCH] HID: usbkbd: return proper error code
@ 2016-08-31 16:28 Sudip Mukherjee
2016-08-31 16:33 ` Fabio Estevam
2016-09-01 11:21 ` Jiri Kosina
0 siblings, 2 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2016-08-31 16:28 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: linux-kernel, linux-usb, linux-input, Sudip Mukherjee
Use proper error code instead of using -1 on failure to allocate
memory. We may use the error code later in the caller.
Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
drivers/hid/usbhid/usbkbd.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
index 9a332e6..ee53359 100644
--- a/drivers/hid/usbhid/usbkbd.c
+++ b/drivers/hid/usbhid/usbkbd.c
@@ -249,15 +249,15 @@ static void usb_kbd_close(struct input_dev *dev)
static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
{
if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
- return -1;
+ return -ENOMEM;
if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL)))
- return -1;
+ return -ENOMEM;
if (!(kbd->new = usb_alloc_coherent(dev, 8, GFP_ATOMIC, &kbd->new_dma)))
- return -1;
+ return -ENOMEM;
if (!(kbd->cr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL)))
- return -1;
+ return -ENOMEM;
if (!(kbd->leds = usb_alloc_coherent(dev, 1, GFP_ATOMIC, &kbd->leds_dma)))
- return -1;
+ return -ENOMEM;
return 0;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] HID: usbkbd: return proper error code
2016-08-31 16:28 [PATCH] HID: usbkbd: return proper error code Sudip Mukherjee
@ 2016-08-31 16:33 ` Fabio Estevam
2016-08-31 17:38 ` Sudip Mukherjee
2016-09-01 11:21 ` Jiri Kosina
1 sibling, 1 reply; 5+ messages in thread
From: Fabio Estevam @ 2016-08-31 16:33 UTC (permalink / raw)
To: Sudip Mukherjee
Cc: Jiri Kosina, Benjamin Tissoires, linux-kernel, USB list,
linux-input
On Wed, Aug 31, 2016 at 1:28 PM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:
> Use proper error code instead of using -1 on failure to allocate
> memory. We may use the error code later in the caller.
>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
> ---
> drivers/hid/usbhid/usbkbd.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
> index 9a332e6..ee53359 100644
> --- a/drivers/hid/usbhid/usbkbd.c
> +++ b/drivers/hid/usbhid/usbkbd.c
> @@ -249,15 +249,15 @@ static void usb_kbd_close(struct input_dev *dev)
> static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
> {
> if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
> - return -1;
> + return -ENOMEM;
While you are it, the code would look better like this:
kbd->irq = usb_alloc_urb(0, GFP_KERNEL)
if (!kbd->irq)
return -ENOMEM;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] HID: usbkbd: return proper error code
2016-08-31 16:33 ` Fabio Estevam
@ 2016-08-31 17:38 ` Sudip Mukherjee
0 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2016-08-31 17:38 UTC (permalink / raw)
To: Fabio Estevam
Cc: Jiri Kosina, Benjamin Tissoires, linux-kernel, USB list,
linux-input
On Wednesday 31 August 2016 10:03 PM, Fabio Estevam wrote:
> On Wed, Aug 31, 2016 at 1:28 PM, Sudip Mukherjee
> <sudipm.mukherjee@gmail.com> wrote:
>> Use proper error code instead of using -1 on failure to allocate
>> memory. We may use the error code later in the caller.
>>
>> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
>> ---
>> drivers/hid/usbhid/usbkbd.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
>> index 9a332e6..ee53359 100644
>> --- a/drivers/hid/usbhid/usbkbd.c
>> +++ b/drivers/hid/usbhid/usbkbd.c
>> @@ -249,15 +249,15 @@ static void usb_kbd_close(struct input_dev *dev)
>> static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
>> {
>> if (!(kbd->irq = usb_alloc_urb(0, GFP_KERNEL)))
>> - return -1;
>> + return -ENOMEM;
>
> While you are it, the code would look better like this:
>
> kbd->irq = usb_alloc_urb(0, GFP_KERNEL)
> if (!kbd->irq)
> return -ENOMEM;
>
Yes, it will. But that will become two changes in one patch. I will send
a series with this sent patch and another patch to reorder the assignment.
regards
sudip
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] HID: usbkbd: return proper error code
2016-08-31 16:28 [PATCH] HID: usbkbd: return proper error code Sudip Mukherjee
2016-08-31 16:33 ` Fabio Estevam
@ 2016-09-01 11:21 ` Jiri Kosina
2016-09-01 17:58 ` Sudip Mukherjee
1 sibling, 1 reply; 5+ messages in thread
From: Jiri Kosina @ 2016-09-01 11:21 UTC (permalink / raw)
To: Sudip Mukherjee; +Cc: Benjamin Tissoires, linux-kernel, linux-usb, linux-input
On Wed, 31 Aug 2016, Sudip Mukherjee wrote:
> Use proper error code instead of using -1 on failure to allocate
> memory. We may use the error code later in the caller.
But we don't. usb_kbd_probe() returns -ENOMEM in case usb_kbd_alloc_mem()
fails anyway, so I fail to see the point of the change really.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] HID: usbkbd: return proper error code
2016-09-01 11:21 ` Jiri Kosina
@ 2016-09-01 17:58 ` Sudip Mukherjee
0 siblings, 0 replies; 5+ messages in thread
From: Sudip Mukherjee @ 2016-09-01 17:58 UTC (permalink / raw)
To: Jiri Kosina; +Cc: Benjamin Tissoires, linux-kernel, linux-usb, linux-input
On Thursday 01 September 2016 04:51 PM, Jiri Kosina wrote:
> On Wed, 31 Aug 2016, Sudip Mukherjee wrote:
>
>> Use proper error code instead of using -1 on failure to allocate
>> memory. We may use the error code later in the caller.
>
> But we don't. usb_kbd_probe() returns -ENOMEM in case usb_kbd_alloc_mem()
> fails anyway, so I fail to see the point of the change really.
>
Well, yes, we don't as of now.
When I was reading the code for something related to my day job I was a
bit confused with -1 instead of a proper error code. I am sure there
will be many others like me.
Its fine if you think the change is not needed.
regards
sudip
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-01 17:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-31 16:28 [PATCH] HID: usbkbd: return proper error code Sudip Mukherjee
2016-08-31 16:33 ` Fabio Estevam
2016-08-31 17:38 ` Sudip Mukherjee
2016-09-01 11:21 ` Jiri Kosina
2016-09-01 17:58 ` Sudip Mukherjee
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).