Re: [ 068/108] HID: hidraw: add proper error handling to raw event reporting

2012-10-09 Thread Ben Hutchings
On Mon, 2012-10-08 at 16:34 -0300, Herton Ronaldo Krzesinski wrote:
> On Sun, Oct 07, 2012 at 11:59:42PM +0100, Ben Hutchings wrote:
> > 3.2-stable review patch.  If anyone has any objections, please let me know.
> > 
> > --
> > 
> > From: Jiri Kosina 
> > 
> > commit b6787242f32700377d3da3b8d788ab3928bab849 upstream.
> > 
> > If kmemdup() in hidraw_report_event() fails, we are not propagating
> > this fact properly.
> > 
> > Let hidraw_report_event() and hid_report_raw_event() return an error
> > value to the caller.
> 
> This needs in addition a small fix on top, commit d6d7c87
> ("HID: fix return value of hidraw_report_event() when !CONFIG_HIDRAW")

I've added that, thanks.

Ben.

-- 
Ben Hutchings
Who are all these weirdos? - David Bowie, about L-Space IRC channel #afp


signature.asc
Description: This is a digitally signed message part


Re: [ 068/108] HID: hidraw: add proper error handling to raw event reporting

2012-10-09 Thread Ben Hutchings
On Mon, 2012-10-08 at 16:34 -0300, Herton Ronaldo Krzesinski wrote:
 On Sun, Oct 07, 2012 at 11:59:42PM +0100, Ben Hutchings wrote:
  3.2-stable review patch.  If anyone has any objections, please let me know.
  
  --
  
  From: Jiri Kosina jkos...@suse.cz
  
  commit b6787242f32700377d3da3b8d788ab3928bab849 upstream.
  
  If kmemdup() in hidraw_report_event() fails, we are not propagating
  this fact properly.
  
  Let hidraw_report_event() and hid_report_raw_event() return an error
  value to the caller.
 
 This needs in addition a small fix on top, commit d6d7c87
 (HID: fix return value of hidraw_report_event() when !CONFIG_HIDRAW)

I've added that, thanks.

Ben.

-- 
Ben Hutchings
Who are all these weirdos? - David Bowie, about L-Space IRC channel #afp


signature.asc
Description: This is a digitally signed message part


Re: [ 068/108] HID: hidraw: add proper error handling to raw event reporting

2012-10-08 Thread Herton Ronaldo Krzesinski
On Sun, Oct 07, 2012 at 11:59:42PM +0100, Ben Hutchings wrote:
> 3.2-stable review patch.  If anyone has any objections, please let me know.
> 
> --
> 
> From: Jiri Kosina 
> 
> commit b6787242f32700377d3da3b8d788ab3928bab849 upstream.
> 
> If kmemdup() in hidraw_report_event() fails, we are not propagating
> this fact properly.
> 
> Let hidraw_report_event() and hid_report_raw_event() return an error
> value to the caller.

This needs in addition a small fix on top, commit d6d7c87
("HID: fix return value of hidraw_report_event() when !CONFIG_HIDRAW")

-- 
[]'s
Herton
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [ 068/108] HID: hidraw: add proper error handling to raw event reporting

2012-10-08 Thread Herton Ronaldo Krzesinski
On Sun, Oct 07, 2012 at 11:59:42PM +0100, Ben Hutchings wrote:
 3.2-stable review patch.  If anyone has any objections, please let me know.
 
 --
 
 From: Jiri Kosina jkos...@suse.cz
 
 commit b6787242f32700377d3da3b8d788ab3928bab849 upstream.
 
 If kmemdup() in hidraw_report_event() fails, we are not propagating
 this fact properly.
 
 Let hidraw_report_event() and hid_report_raw_event() return an error
 value to the caller.

This needs in addition a small fix on top, commit d6d7c87
(HID: fix return value of hidraw_report_event() when !CONFIG_HIDRAW)

-- 
[]'s
Herton
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[ 068/108] HID: hidraw: add proper error handling to raw event reporting

2012-10-07 Thread Ben Hutchings
3.2-stable review patch.  If anyone has any objections, please let me know.

--

From: Jiri Kosina 

commit b6787242f32700377d3da3b8d788ab3928bab849 upstream.

If kmemdup() in hidraw_report_event() fails, we are not propagating
this fact properly.

Let hidraw_report_event() and hid_report_raw_event() return an error
value to the caller.

Reported-by: Oliver Neukum 
Signed-off-by: Jiri Kosina 
Signed-off-by: Ben Hutchings 
---
 drivers/hid/hid-core.c |   16 +++-
 drivers/hid/hidraw.c   |   19 +--
 include/linux/hid.h|2 +-
 include/linux/hidraw.h |4 ++--
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 8be458b..0cddcaa 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1032,7 +1032,7 @@ static struct hid_report *hid_get_report(struct 
hid_report_enum *report_enum,
return report;
 }
 
-void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
+int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
int interrupt)
 {
struct hid_report_enum *report_enum = hid->report_enum + type;
@@ -1040,10 +1040,11 @@ void hid_report_raw_event(struct hid_device *hid, int 
type, u8 *data, int size,
unsigned int a;
int rsize, csize = size;
u8 *cdata = data;
+   int ret = 0;
 
report = hid_get_report(report_enum, data);
if (!report)
-   return;
+   goto out;
 
if (report_enum->numbered) {
cdata++;
@@ -1063,14 +1064,19 @@ void hid_report_raw_event(struct hid_device *hid, int 
type, u8 *data, int size,
 
if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
hid->hiddev_report_event(hid, report);
-   if (hid->claimed & HID_CLAIMED_HIDRAW)
-   hidraw_report_event(hid, data, size);
+   if (hid->claimed & HID_CLAIMED_HIDRAW) {
+   ret = hidraw_report_event(hid, data, size);
+   if (ret)
+   goto out;
+   }
 
for (a = 0; a < report->maxfield; a++)
hid_input_field(hid, report->field[a], cdata, interrupt);
 
if (hid->claimed & HID_CLAIMED_INPUT)
hidinput_report_event(hid, report);
+out:
+   return ret;
 }
 EXPORT_SYMBOL_GPL(hid_report_raw_event);
 
@@ -1147,7 +1153,7 @@ nomem:
}
}
 
-   hid_report_raw_event(hid, type, data, size, interrupt);
+   ret = hid_report_raw_event(hid, type, data, size, interrupt);
 
 unlock:
up(>driver_lock);
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index cf7d6d5..36fa77b 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -87,11 +87,13 @@ static ssize_t hidraw_read(struct file *file, char __user 
*buffer, size_t count,
len = list->buffer[list->tail].len > count ?
count : list->buffer[list->tail].len;
 
-   if (copy_to_user(buffer, list->buffer[list->tail].value, len)) {
-   ret = -EFAULT;
-   goto out;
+   if (list->buffer[list->tail].value) {
+   if (copy_to_user(buffer, 
list->buffer[list->tail].value, len)) {
+   ret = -EFAULT;
+   goto out;
+   }
+   ret = len;
}
-   ret = len;
 
kfree(list->buffer[list->tail].value);
list->tail = (list->tail + 1) & (HIDRAW_BUFFER_SIZE - 1);
@@ -437,19 +439,24 @@ static const struct file_operations hidraw_ops = {
.llseek =   noop_llseek,
 };
 
-void hidraw_report_event(struct hid_device *hid, u8 *data, int len)
+int hidraw_report_event(struct hid_device *hid, u8 *data, int len)
 {
struct hidraw *dev = hid->hidraw;
struct hidraw_list *list;
+   int ret = 0;
 
list_for_each_entry(list, >list, node) {
-   list->buffer[list->head].value = kmemdup(data, len, GFP_ATOMIC);
+   if (!(list->buffer[list->head].value = kmemdup(data, len, 
GFP_ATOMIC))) {
+   ret = -ENOMEM;
+   break;
+   }
list->buffer[list->head].len = len;
list->head = (list->head + 1) & (HIDRAW_BUFFER_SIZE - 1);
kill_fasync(>fasync, SIGIO, POLL_IN);
}
 
wake_up_interruptible(>wait);
+   return ret;
 }
 EXPORT_SYMBOL_GPL(hidraw_report_event);
 
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 3a95da6..58b3857 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -896,7 +896,7 @@ static inline int hid_hw_power(struct hid_device *hdev, int 
level)
return hdev->ll_driver->power ? hdev->ll_driver->power(hdev, level) : 0;
 }
 
-void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,

[ 068/108] HID: hidraw: add proper error handling to raw event reporting

2012-10-07 Thread Ben Hutchings
3.2-stable review patch.  If anyone has any objections, please let me know.

--

From: Jiri Kosina jkos...@suse.cz

commit b6787242f32700377d3da3b8d788ab3928bab849 upstream.

If kmemdup() in hidraw_report_event() fails, we are not propagating
this fact properly.

Let hidraw_report_event() and hid_report_raw_event() return an error
value to the caller.

Reported-by: Oliver Neukum oneu...@suse.de
Signed-off-by: Jiri Kosina jkos...@suse.cz
Signed-off-by: Ben Hutchings b...@decadent.org.uk
---
 drivers/hid/hid-core.c |   16 +++-
 drivers/hid/hidraw.c   |   19 +--
 include/linux/hid.h|2 +-
 include/linux/hidraw.h |4 ++--
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 8be458b..0cddcaa 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1032,7 +1032,7 @@ static struct hid_report *hid_get_report(struct 
hid_report_enum *report_enum,
return report;
 }
 
-void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
+int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
int interrupt)
 {
struct hid_report_enum *report_enum = hid-report_enum + type;
@@ -1040,10 +1040,11 @@ void hid_report_raw_event(struct hid_device *hid, int 
type, u8 *data, int size,
unsigned int a;
int rsize, csize = size;
u8 *cdata = data;
+   int ret = 0;
 
report = hid_get_report(report_enum, data);
if (!report)
-   return;
+   goto out;
 
if (report_enum-numbered) {
cdata++;
@@ -1063,14 +1064,19 @@ void hid_report_raw_event(struct hid_device *hid, int 
type, u8 *data, int size,
 
if ((hid-claimed  HID_CLAIMED_HIDDEV)  hid-hiddev_report_event)
hid-hiddev_report_event(hid, report);
-   if (hid-claimed  HID_CLAIMED_HIDRAW)
-   hidraw_report_event(hid, data, size);
+   if (hid-claimed  HID_CLAIMED_HIDRAW) {
+   ret = hidraw_report_event(hid, data, size);
+   if (ret)
+   goto out;
+   }
 
for (a = 0; a  report-maxfield; a++)
hid_input_field(hid, report-field[a], cdata, interrupt);
 
if (hid-claimed  HID_CLAIMED_INPUT)
hidinput_report_event(hid, report);
+out:
+   return ret;
 }
 EXPORT_SYMBOL_GPL(hid_report_raw_event);
 
@@ -1147,7 +1153,7 @@ nomem:
}
}
 
-   hid_report_raw_event(hid, type, data, size, interrupt);
+   ret = hid_report_raw_event(hid, type, data, size, interrupt);
 
 unlock:
up(hid-driver_lock);
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index cf7d6d5..36fa77b 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -87,11 +87,13 @@ static ssize_t hidraw_read(struct file *file, char __user 
*buffer, size_t count,
len = list-buffer[list-tail].len  count ?
count : list-buffer[list-tail].len;
 
-   if (copy_to_user(buffer, list-buffer[list-tail].value, len)) {
-   ret = -EFAULT;
-   goto out;
+   if (list-buffer[list-tail].value) {
+   if (copy_to_user(buffer, 
list-buffer[list-tail].value, len)) {
+   ret = -EFAULT;
+   goto out;
+   }
+   ret = len;
}
-   ret = len;
 
kfree(list-buffer[list-tail].value);
list-tail = (list-tail + 1)  (HIDRAW_BUFFER_SIZE - 1);
@@ -437,19 +439,24 @@ static const struct file_operations hidraw_ops = {
.llseek =   noop_llseek,
 };
 
-void hidraw_report_event(struct hid_device *hid, u8 *data, int len)
+int hidraw_report_event(struct hid_device *hid, u8 *data, int len)
 {
struct hidraw *dev = hid-hidraw;
struct hidraw_list *list;
+   int ret = 0;
 
list_for_each_entry(list, dev-list, node) {
-   list-buffer[list-head].value = kmemdup(data, len, GFP_ATOMIC);
+   if (!(list-buffer[list-head].value = kmemdup(data, len, 
GFP_ATOMIC))) {
+   ret = -ENOMEM;
+   break;
+   }
list-buffer[list-head].len = len;
list-head = (list-head + 1)  (HIDRAW_BUFFER_SIZE - 1);
kill_fasync(list-fasync, SIGIO, POLL_IN);
}
 
wake_up_interruptible(dev-wait);
+   return ret;
 }
 EXPORT_SYMBOL_GPL(hidraw_report_event);
 
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 3a95da6..58b3857 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -896,7 +896,7 @@ static inline int hid_hw_power(struct hid_device *hdev, int 
level)
return hdev-ll_driver-power ? hdev-ll_driver-power(hdev, level) : 0;
 }
 
-void hid_report_raw_event(struct hid_device *hid,