Commit d4f0e4da authored by Havard Skinnemoen's avatar Havard Skinnemoen Committed by Jiri Kosina

HID: hiddev: Use vzalloc to allocate hiddev_list

Everytime a HID device is opened, a new hiddev_list is allocated with
kzalloc. This requires 64KB of physically contiguous memory, which could
easily push a heavily loaded system over the edge.

Allocating the same amount of memory with vmalloc shouldn't be nearly as
demanding, so let's do that instead. The memory isn't used for DMA and
doesn't look particularly performance sensitive, so this should be safe.
Signed-off-by: default avatarHavard Skinnemoen <hskinnemoen@google.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 9f1f463a
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/hid.h> #include <linux/hid.h>
#include <linux/hiddev.h> #include <linux/hiddev.h>
#include <linux/compat.h> #include <linux/compat.h>
#include <linux/vmalloc.h>
#include "usbhid.h" #include "usbhid.h"
#ifdef CONFIG_USB_DYNAMIC_MINORS #ifdef CONFIG_USB_DYNAMIC_MINORS
...@@ -250,13 +251,13 @@ static int hiddev_release(struct inode * inode, struct file * file) ...@@ -250,13 +251,13 @@ static int hiddev_release(struct inode * inode, struct file * file)
} else { } else {
mutex_unlock(&list->hiddev->existancelock); mutex_unlock(&list->hiddev->existancelock);
kfree(list->hiddev); kfree(list->hiddev);
kfree(list); vfree(list);
return 0; return 0;
} }
} }
mutex_unlock(&list->hiddev->existancelock); mutex_unlock(&list->hiddev->existancelock);
kfree(list); vfree(list);
return 0; return 0;
} }
...@@ -278,7 +279,7 @@ static int hiddev_open(struct inode *inode, struct file *file) ...@@ -278,7 +279,7 @@ static int hiddev_open(struct inode *inode, struct file *file)
hid = usb_get_intfdata(intf); hid = usb_get_intfdata(intf);
hiddev = hid->hiddev; hiddev = hid->hiddev;
if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) if (!(list = vzalloc(sizeof(struct hiddev_list))))
return -ENOMEM; return -ENOMEM;
mutex_init(&list->thread_lock); mutex_init(&list->thread_lock);
list->hiddev = hiddev; list->hiddev = hiddev;
...@@ -322,7 +323,7 @@ static int hiddev_open(struct inode *inode, struct file *file) ...@@ -322,7 +323,7 @@ static int hiddev_open(struct inode *inode, struct file *file)
mutex_unlock(&hiddev->existancelock); mutex_unlock(&hiddev->existancelock);
bail: bail:
file->private_data = NULL; file->private_data = NULL;
kfree(list); vfree(list);
return res; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment