]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
HID: hidraw: add proper error handling to raw event reporting
authorJiri Kosina <jkosina@suse.cz>
Thu, 26 Apr 2012 22:56:08 +0000 (00:56 +0200)
committerJiri Kosina <jkosina@suse.cz>
Fri, 27 Apr 2012 18:10:09 +0000 (20:10 +0200)
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 <oneukum@suse.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-core.c
drivers/hid/hidraw.c
include/linux/hid.h
include/linux/hidraw.h

index 8be458b79b2c6efbd2a1df8c7a7fc5a419c167bc..0cddcaa3fe7fe00b2999dcea044708ca4c572b61 100644 (file)
@@ -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);
index cf7d6d58e79f25513dd0baedac00e3ddfd5f342f..36fa77b40ffbfcccabed691700d787bc10ea8402 100644 (file)
@@ -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);
 
index 3a95da60fd3e5cda95617fffc824168437373d95..58b3857dc51c241eab479f286be6befde4b147a0 100644 (file)
@@ -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,
+int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
                int interrupt);
 
 extern int hid_generic_init(void);
index 4b88e697c4e9b4367a8620b0cd0d2c55ee968dc7..9cdc9b67ff49eaa5b5f34193f9e6f548afb641f6 100644 (file)
@@ -76,13 +76,13 @@ struct hidraw_list {
 #ifdef CONFIG_HIDRAW
 int hidraw_init(void);
 void hidraw_exit(void);
-void hidraw_report_event(struct hid_device *, u8 *, int);
+int hidraw_report_event(struct hid_device *, u8 *, int);
 int hidraw_connect(struct hid_device *);
 void hidraw_disconnect(struct hid_device *);
 #else
 static inline int hidraw_init(void) { return 0; }
 static inline void hidraw_exit(void) { }
-static inline void hidraw_report_event(struct hid_device *hid, u8 *data, int len) { }
+static inline int hidraw_report_event(struct hid_device *hid, u8 *data, int len) { }
 static inline int hidraw_connect(struct hid_device *hid) { return -1; }
 static inline void hidraw_disconnect(struct hid_device *hid) { }
 #endif