summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMariusz Kozlowski <m.kozlowski@tuxland.pl>2007-09-27 11:24:55 +0200
committerJiri Kosina <jkosina@suse.cz>2007-10-14 14:47:26 +0200
commit709d27c04f4eccbc99d57a5569bce028915a4345 (patch)
treed7d95f51bb618f2e8559a83ea0418b7d8476e79b /drivers
parent86166b7bcda0bcb53525114fa1c87ac432be478e (diff)
downloadlinux-709d27c04f4eccbc99d57a5569bce028915a4345.tar.bz2
HID: hidraw_connect() memleak fix
It looks like hidraw_connect() is leaking memory in case of failure. Also it should return -ENOMEM when kzalloc fails. Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hid/hidraw.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index 20ebba1032b8..8503197a8131 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(hidraw_report_event);
int hidraw_connect(struct hid_device *hid)
{
- int minor, result = -EINVAL;
+ int minor, result;
struct hidraw *dev;
/* TODO currently we accept any HID device. This should later
@@ -290,8 +290,11 @@ int hidraw_connect(struct hid_device *hid)
* non-input applications
*/
- if (!(dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL)))
- return -1;
+ dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
+ if (!dev)
+ return -ENOMEM;
+
+ result = -EINVAL;
spin_lock(&minors_lock);
@@ -305,8 +308,10 @@ int hidraw_connect(struct hid_device *hid)
spin_unlock(&minors_lock);
- if (result)
+ if (result) {
+ kfree(dev);
goto out;
+ }
dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor),
"%s%d", "hidraw", minor);
@@ -316,6 +321,7 @@ int hidraw_connect(struct hid_device *hid)
hidraw_table[minor] = NULL;
spin_unlock(&minors_lock);
result = PTR_ERR(dev->dev);
+ kfree(dev);
goto out;
}