linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure
@ 2012-11-21  6:20 Sachin Kamat
  2012-11-21  6:20 ` [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning Sachin Kamat
  2012-11-22 21:03 ` [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Jiri Kosina
  0 siblings, 2 replies; 10+ messages in thread
From: Sachin Kamat @ 2012-11-21  6:20 UTC (permalink / raw)
  To: linux-input; +Cc: jkosina, jic23, sachin.kamat, patches

Silences the following smatch warning:
drivers/hid/usbhid/hiddev.c:897 hiddev_connect() warn:
returning -1 instead of -ENOMEM is sloppy

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/hid/usbhid/hiddev.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 14599e2..50e2ab8 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -894,7 +894,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
 	}
 
 	if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
-		return -1;
+		return -ENOMEM;
 
 	init_waitqueue_head(&hiddev->wait);
 	INIT_LIST_HEAD(&hiddev->list);
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning
  2012-11-21  6:20 [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Sachin Kamat
@ 2012-11-21  6:20 ` Sachin Kamat
  2012-11-21 12:42   ` Alan Cox
  2012-11-22 21:03 ` [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Jiri Kosina
  1 sibling, 1 reply; 10+ messages in thread
From: Sachin Kamat @ 2012-11-21  6:20 UTC (permalink / raw)
  To: linux-input; +Cc: jkosina, jic23, sachin.kamat, patches, Srinivas Pandruvada

This avoids a possible NULL pointer dereference error when report
is NULL.

Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
 drivers/hid/hid-sensor-hub.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index d9d73e9..29f8071 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -428,6 +428,9 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
 	struct hid_collection *collection = NULL;
 	void *priv = NULL;
 
+	if (!report)
+		goto err_report;
+
 	hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
 			 report->id, size, report->type);
 	hid_dbg(hdev, "maxfield:%d\n", report->maxfield);
@@ -437,9 +440,6 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
 	ptr = raw_data;
 	ptr++; /*Skip report id*/
 
-	if (!report)
-		goto err_report;
-
 	spin_lock_irqsave(&pdata->lock, flags);
 
 	for (i = 0; i < report->maxfield; ++i) {
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning
  2012-11-21  6:20 ` [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning Sachin Kamat
@ 2012-11-21 12:42   ` Alan Cox
  2012-11-21 17:11     ` Srinivas Pandruvada
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Cox @ 2012-11-21 12:42 UTC (permalink / raw)
  To: Sachin Kamat; +Cc: linux-input, jkosina, jic23, patches, Srinivas Pandruvada

On Wed, 21 Nov 2012 11:50:30 +0530
Sachin Kamat <sachin.kamat@linaro.org> wrote:

> This avoids a possible NULL pointer dereference error when report
> is NULL.

This is wrong. Please see the patch I sent a while ago - it can't be
NULL, the check just needs removing.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning
  2012-11-21 12:42   ` Alan Cox
@ 2012-11-21 17:11     ` Srinivas Pandruvada
  2012-11-21 22:26       ` Jiri Kosina
  0 siblings, 1 reply; 10+ messages in thread
From: Srinivas Pandruvada @ 2012-11-21 17:11 UTC (permalink / raw)
  To: Alan Cox, jic23; +Cc: Sachin Kamat, linux-input, jkosina, patches

Hi Jonathan,

Please check and merge Alan Cox's patch. I have forwarded this patch to you.

Thanks,
Srinivas


On 11/21/2012 04:42 AM, Alan Cox wrote:
> On Wed, 21 Nov 2012 11:50:30 +0530
> Sachin Kamat <sachin.kamat@linaro.org> wrote:
>
>> This avoids a possible NULL pointer dereference error when report
>> is NULL.
> This is wrong. Please see the patch I sent a while ago - it can't be
> NULL, the check just needs removing.
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning
  2012-11-21 17:11     ` Srinivas Pandruvada
@ 2012-11-21 22:26       ` Jiri Kosina
  0 siblings, 0 replies; 10+ messages in thread
From: Jiri Kosina @ 2012-11-21 22:26 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: Alan Cox, jic23, Sachin Kamat, linux-input, patches

On Wed, 21 Nov 2012, Srinivas Pandruvada wrote:

> Please check and merge Alan Cox's patch. I have forwarded this patch to you.

I have already applied the patch to my tree.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure
  2012-11-21  6:20 [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Sachin Kamat
  2012-11-21  6:20 ` [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning Sachin Kamat
@ 2012-11-22 21:03 ` Jiri Kosina
  2012-11-26 18:05   ` Dmitry Torokhov
  1 sibling, 1 reply; 10+ messages in thread
From: Jiri Kosina @ 2012-11-22 21:03 UTC (permalink / raw)
  To: Sachin Kamat; +Cc: linux-input, jic23, patches

On Wed, 21 Nov 2012, Sachin Kamat wrote:

> Silences the following smatch warning:
> drivers/hid/usbhid/hiddev.c:897 hiddev_connect() warn:
> returning -1 instead of -ENOMEM is sloppy
> 
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
>  drivers/hid/usbhid/hiddev.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
> index 14599e2..50e2ab8 100644
> --- a/drivers/hid/usbhid/hiddev.c
> +++ b/drivers/hid/usbhid/hiddev.c
> @@ -894,7 +894,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
>  	}
>  
>  	if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
> -		return -1;
> +		return -ENOMEM;
>  
>  	init_waitqueue_head(&hiddev->wait);
>  	INIT_LIST_HEAD(&hiddev->list);

Well, this would make sense only if the callers would be actualling doing 
something useful with that return value. But the only check we are 
performing at callsites is non-zero test ...

Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure
  2012-11-22 21:03 ` [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Jiri Kosina
@ 2012-11-26 18:05   ` Dmitry Torokhov
  2012-11-26 22:09     ` Jiri Kosina
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Torokhov @ 2012-11-26 18:05 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Sachin Kamat, linux-input, jic23, patches

On Thu, Nov 22, 2012 at 10:03:44PM +0100, Jiri Kosina wrote:
> On Wed, 21 Nov 2012, Sachin Kamat wrote:
> 
> > Silences the following smatch warning:
> > drivers/hid/usbhid/hiddev.c:897 hiddev_connect() warn:
> > returning -1 instead of -ENOMEM is sloppy
> > 
> > Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> > ---
> >  drivers/hid/usbhid/hiddev.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
> > index 14599e2..50e2ab8 100644
> > --- a/drivers/hid/usbhid/hiddev.c
> > +++ b/drivers/hid/usbhid/hiddev.c
> > @@ -894,7 +894,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
> >  	}
> >  
> >  	if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
> > -		return -1;
> > +		return -ENOMEM;
> >  
> >  	init_waitqueue_head(&hiddev->wait);
> >  	INIT_LIST_HEAD(&hiddev->list);
> 
> Well, this would make sense only if the callers would be actualling doing 
> something useful with that return value. But the only check we are 
> performing at callsites is non-zero test ...

It is chicken and egg problem - callers can't use the result unless it
is meaningful and callee's do not bother to send anything meaningful
because nobody uses it...

If someone takes time to convert to proper return codes I think it would
be a good thing.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure
  2012-11-26 18:05   ` Dmitry Torokhov
@ 2012-11-26 22:09     ` Jiri Kosina
  2012-11-27  4:42       ` Sachin Kamat
  0 siblings, 1 reply; 10+ messages in thread
From: Jiri Kosina @ 2012-11-26 22:09 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: Sachin Kamat, linux-input, jic23, patches

On Mon, 26 Nov 2012, Dmitry Torokhov wrote:

> > > Silences the following smatch warning:
> > > drivers/hid/usbhid/hiddev.c:897 hiddev_connect() warn:
> > > returning -1 instead of -ENOMEM is sloppy
> > > 
> > > Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> > > ---
> > >  drivers/hid/usbhid/hiddev.c |    2 +-
> > >  1 files changed, 1 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
> > > index 14599e2..50e2ab8 100644
> > > --- a/drivers/hid/usbhid/hiddev.c
> > > +++ b/drivers/hid/usbhid/hiddev.c
> > > @@ -894,7 +894,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
> > >  	}
> > >  
> > >  	if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
> > > -		return -1;
> > > +		return -ENOMEM;
> > >  
> > >  	init_waitqueue_head(&hiddev->wait);
> > >  	INIT_LIST_HEAD(&hiddev->list);
> > 
> > Well, this would make sense only if the callers would be actualling doing 
> > something useful with that return value. But the only check we are 
> > performing at callsites is non-zero test ...
> 
> It is chicken and egg problem - callers can't use the result unless it
> is meaningful and callee's do not bother to send anything meaningful
> because nobody uses it...
> 
> If someone takes time to convert to proper return codes I think it would
> be a good thing.

Fully agree with you.

But I'd like to have both sides changed together once someone starts 
taking care of fixing it.

Thanks,

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure
  2012-11-26 22:09     ` Jiri Kosina
@ 2012-11-27  4:42       ` Sachin Kamat
  2012-11-27  9:55         ` Jiri Kosina
  0 siblings, 1 reply; 10+ messages in thread
From: Sachin Kamat @ 2012-11-27  4:42 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Dmitry Torokhov, linux-input, jic23, patches

Hi Jiri,

On 27 November 2012 03:39, Jiri Kosina <jkosina@suse.cz> wrote:
> On Mon, 26 Nov 2012, Dmitry Torokhov wrote:
>
>> > > Silences the following smatch warning:
>> > > drivers/hid/usbhid/hiddev.c:897 hiddev_connect() warn:
>> > > returning -1 instead of -ENOMEM is sloppy
>> > >
>> > > Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> > > ---
>> > >  drivers/hid/usbhid/hiddev.c |    2 +-
>> > >  1 files changed, 1 insertions(+), 1 deletions(-)
>> > >
>> > > diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
>> > > index 14599e2..50e2ab8 100644
>> > > --- a/drivers/hid/usbhid/hiddev.c
>> > > +++ b/drivers/hid/usbhid/hiddev.c
>> > > @@ -894,7 +894,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force)
>> > >   }
>> > >
>> > >   if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
>> > > -         return -1;
>> > > +         return -ENOMEM;
>> > >
>> > >   init_waitqueue_head(&hiddev->wait);
>> > >   INIT_LIST_HEAD(&hiddev->list);
>> >
>> > Well, this would make sense only if the callers would be actualling doing
>> > something useful with that return value. But the only check we are
>> > performing at callsites is non-zero test ...
>>
>> It is chicken and egg problem - callers can't use the result unless it
>> is meaningful and callee's do not bother to send anything meaningful
>> because nobody uses it...
>>
>> If someone takes time to convert to proper return codes I think it would
>> be a good thing.
>
> Fully agree with you.
>
> But I'd like to have both sides changed together once someone starts
> taking care of fixing it.

The proposed change is done in the function hiddev_connect which
returns 0 on success.
The caller only checks if the return value is 0 or not
(!hdev->hiddev_connect(...)). In this case
what is the change that you would like to see on the caller side?

>
> Thanks,
>
> --
> Jiri Kosina
> SUSE Labs



-- 
With warm regards,
Sachin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure
  2012-11-27  4:42       ` Sachin Kamat
@ 2012-11-27  9:55         ` Jiri Kosina
  0 siblings, 0 replies; 10+ messages in thread
From: Jiri Kosina @ 2012-11-27  9:55 UTC (permalink / raw)
  To: Sachin Kamat; +Cc: Dmitry Torokhov, linux-input, jic23, patches

On Tue, 27 Nov 2012, Sachin Kamat wrote:

> > Fully agree with you.
> >
> > But I'd like to have both sides changed together once someone starts
> > taking care of fixing it.
> 
> The proposed change is done in the function hiddev_connect which
> returns 0 on success.
> The caller only checks if the return value is 0 or not
> (!hdev->hiddev_connect(...)). In this case
> what is the change that you would like to see on the caller side?

A check whether the value returned by hiddev_connect() is error code 
(through IS_ERR_VALUE() or something similar), and continue propagating 
the error out of hid_connect().

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-11-27  9:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-21  6:20 [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Sachin Kamat
2012-11-21  6:20 ` [PATCH 2/2] hid: hid-sensor-hub: Move NULL check to beginning Sachin Kamat
2012-11-21 12:42   ` Alan Cox
2012-11-21 17:11     ` Srinivas Pandruvada
2012-11-21 22:26       ` Jiri Kosina
2012-11-22 21:03 ` [PATCH 1/2] hid: usbhid: Return -ENOMEM instead of -1 for memory allocation failure Jiri Kosina
2012-11-26 18:05   ` Dmitry Torokhov
2012-11-26 22:09     ` Jiri Kosina
2012-11-27  4:42       ` Sachin Kamat
2012-11-27  9:55         ` Jiri Kosina

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).