diff mbox

[2/2] hid: hid-sensor-hub: Move NULL check to beginning

Message ID 1353478830-23788-2-git-send-email-sachin.kamat@linaro.org
State Rejected
Headers show

Commit Message

Sachin Kamat Nov. 21, 2012, 6:20 a.m. UTC
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(-)

Comments

Alan Cox Nov. 21, 2012, 12:42 p.m. UTC | #1
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.
Srinivas Pandruvada Nov. 21, 2012, 5:11 p.m. UTC | #2
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.
>
Jiri Kosina Nov. 21, 2012, 10:26 p.m. UTC | #3
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.
diff mbox

Patch

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