Re: 2.6.21-rc3-mm1

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jiri Kosina
Date: Saturday, March 10, 2007 - 5:43 am

On Sat, 10 Mar 2007, Greg KH wrote:


Hi,

I have just queued the patch below to HID tree for the next upstream 
merge. Mariusz, I guess it solves your issue, right?

I have already been talking with Vojtech some time ago that rewritting the 
hid parser so that it would use less memory (but probably slightly a bit 
more CPU) would be a good thing to do, and it's been sitting in my TODO 
list for quite some time already. It's really not a straightforward 
rewrite, so I would incline to use the vmalloc() solution until the parser 
code has been rewritten. The hid_parser structure in question is living 
for very short time anyway, so it shouldn't be that big issue.

Thanks.


From: Jiri Kosina <jkosina@suse.cz>
Subject: [PATCH] HID: allocate hid_parser through vmalloc()

hid_parser is non-trivially large structure, so it should be allocated
using vmalloc() to avoid unsuccessful allocations when memory fragmentation
is too high.
This structue has a very short life, it's destroyed as soon as the report
descriptor has been completely parsed.

This should be considered a temporary solution, until the hid_parser is
rewritten to consume less memory during report descriptor parsing.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
 drivers/hid/hid-core.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index f4ee1af..e5894a7 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -26,6 +26,7 @@
 #include <asm/byteorder.h>
 #include <linux/input.h>
 #include <linux/wait.h>
+#include <linux/vmalloc.h>
 
 #include <linux/hid.h>
 #include <linux/hiddev.h>
@@ -654,12 +655,13 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
 	memcpy(device->rdesc, start, size);
 	device->rsize = size;
 
-	if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
+	if (!(parser = vmalloc(sizeof(struct hid_parser)))) {
 		kfree(device->rdesc);
 		kfree(device->collection);
 		kfree(device);
 		return NULL;
 	}
+	memset(parser, 0, sizeof(struct hid_parser));
 	parser->device = device;
 
 	end = start + size;
@@ -668,7 +670,7 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
 		if (item.format != HID_ITEM_FORMAT_SHORT) {
 			dbg("unexpected long global item");
 			hid_free_device(device);
-			kfree(parser);
+			vfree(parser);
 			return NULL;
 		}
 
@@ -676,7 +678,7 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
 			dbg("item %u %u %u %u parsing failed\n",
 				item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
 			hid_free_device(device);
-			kfree(parser);
+			vfree(parser);
 			return NULL;
 		}
 
@@ -684,23 +686,23 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
 			if (parser->collection_stack_ptr) {
 				dbg("unbalanced collection at end of report description");
 				hid_free_device(device);
-				kfree(parser);
+				vfree(parser);
 				return NULL;
 			}
 			if (parser->local.delimiter_depth) {
 				dbg("unbalanced delimiter at end of report description");
 				hid_free_device(device);
-				kfree(parser);
+				vfree(parser);
 				return NULL;
 			}
-			kfree(parser);
+			vfree(parser);
 			return device;
 		}
 	}
 
 	dbg("item fetching failed at offset %d\n", (int)(end - start));
 	hid_free_device(device);
-	kfree(parser);
+	vfree(parser);
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(hid_parse_report);

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
2.6.21-rc3-mm1, Andrew Morton, (Wed Mar 7, 9:18 pm)
ext4, wireless (was Re: 2.6.21-rc3-mm1), Jeff Garzik, (Thu Mar 8, 2:59 am)
Re: 2.6.21-rc3-mm1, John W. Linville, (Thu Mar 8, 7:50 am)
Re: 2.6.21-rc3-mm1, Dave Jones, (Thu Mar 8, 9:37 am)
Re: 2.6.21-rc3-mm1, Valdis.Kletnieks, (Thu Mar 8, 10:56 am)
Re: 2.6.21-rc3-mm1, John W. Linville, (Thu Mar 8, 11:34 am)
Re: 2.6.21-rc3-mm1, Valdis.Kletnieks, (Thu Mar 8, 1:27 pm)
Re: 2.6.21-rc3-mm1, Michal Piotrowski, (Thu Mar 8, 1:50 pm)
Re: 2.6.21-rc3-mm1, Frederik Deweerdt, (Fri Mar 9, 4:40 am)
Re: 2.6.21-rc3-mm1, Andrew Morton, (Fri Mar 9, 7:18 pm)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Sat Mar 10, 1:33 am)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Sat Mar 10, 1:48 am)
Re: 2.6.21-rc3-mm1, Andrew Morton, (Sat Mar 10, 1:58 am)
Re: 2.6.21-rc3-mm1, Greg KH, (Sat Mar 10, 2:18 am)
Re: 2.6.21-rc3-mm1, Jiri Kosina, (Sat Mar 10, 5:43 am)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Sat Mar 10, 6:32 am)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Sat Mar 10, 8:36 am)
Re: 2.6.21-rc3-mm1, Paul E. McKenney, (Sat Mar 10, 8:45 am)
Re: [linux-usb-devel] 2.6.21-rc3-mm1, Alan Stern, (Sat Mar 10, 9:00 am)
Re: [linux-usb-devel] 2.6.21-rc3-mm1, Mariusz Kozlowski, (Sat Mar 10, 9:36 am)
Re: [linux-usb-devel] 2.6.21-rc3-mm1, Alan Stern, (Sat Mar 10, 12:02 pm)
Re: 2.6.21-rc3-mm1, Radoslaw Szkodzinski, (Mon Mar 12, 11:14 am)
Re: [linux-usb-devel] 2.6.21-rc3-mm1, Mariusz Kozlowski, (Mon Mar 12, 1:50 pm)
Re: [linux-usb-devel] 2.6.21-rc3-mm1, Jiri Kosina, (Mon Mar 12, 1:53 pm)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Wed Mar 14, 12:06 pm)
Re: 2.6.21-rc3-mm1, Andrew Morton, (Wed Mar 14, 6:07 pm)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Wed Mar 14, 11:09 pm)
ipw2200: can't load firmware (was Re: 2.6.21-rc3-mm1), Frederik Deweerdt, (Thu Mar 15, 2:22 am)
Re: 2.6.21-rc3-mm1, Mel Gorman, (Thu Mar 15, 3:16 am)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Thu Mar 15, 8:37 am)
Re: 2.6.21-rc3-mm1, Mel Gorman, (Thu Mar 15, 12:59 pm)
Re: 2.6.21-rc3-mm1, Mariusz Kozlowski, (Thu Mar 15, 11:43 pm)
Re: 2.6.21-rc3-mm1, Mel Gorman, (Fri Mar 16, 3:03 am)