aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hidraw.c
diff options
context:
space:
mode:
authorMariusz Kozlowski <m.kozlowski@tuxland.pl>2007-09-27 05:24:55 -0400
committerJiri Kosina <jkosina@suse.cz>2007-10-14 08:47:26 -0400
commit709d27c04f4eccbc99d57a5569bce028915a4345 (patch)
treed7d95f51bb618f2e8559a83ea0418b7d8476e79b /drivers/hid/hidraw.c
parent86166b7bcda0bcb53525114fa1c87ac432be478e (diff)
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/hid/hidraw.c')
-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);
282 282
283int hidraw_connect(struct hid_device *hid) 283int hidraw_connect(struct hid_device *hid)
284{ 284{
285 int minor, result = -EINVAL; 285 int minor, result;
286 struct hidraw *dev; 286 struct hidraw *dev;
287 287
288 /* TODO currently we accept any HID device. This should later 288 /* TODO currently we accept any HID device. This should later
@@ -290,8 +290,11 @@ int hidraw_connect(struct hid_device *hid)
290 * non-input applications 290 * non-input applications
291 */ 291 */
292 292
293 if (!(dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL))) 293 dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL);
294 return -1; 294 if (!dev)
295 return -ENOMEM;
296
297 result = -EINVAL;
295 298
296 spin_lock(&minors_lock); 299 spin_lock(&minors_lock);
297 300
@@ -305,8 +308,10 @@ int hidraw_connect(struct hid_device *hid)
305 308
306 spin_unlock(&minors_lock); 309 spin_unlock(&minors_lock);
307 310
308 if (result) 311 if (result) {
312 kfree(dev);
309 goto out; 313 goto out;
314 }
310 315
311 dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor), 316 dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor),
312 "%s%d", "hidraw", minor); 317 "%s%d", "hidraw", minor);
@@ -316,6 +321,7 @@ int hidraw_connect(struct hid_device *hid)
316 hidraw_table[minor] = NULL; 321 hidraw_table[minor] = NULL;
317 spin_unlock(&minors_lock); 322 spin_unlock(&minors_lock);
318 result = PTR_ERR(dev->dev); 323 result = PTR_ERR(dev->dev);
324 kfree(dev);
319 goto out; 325 goto out;
320 } 326 }
321 327