RE: possible missing error handling in hidraw
From: James Woodcock <hidden>
Date: 2012-04-27 07:36:28
From: linux-input-owner@vger.kernel.org [mailto:linux-input-owner@vger.kernel.org] On Behalf Of Jiri Kosina
-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; }
What happens if there is more than 1 element in the list and kmemdup fails halfway through the list? Will the allocated memory leak the next time hirdaw_report_event() is called? James