diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-07-29 11:14:17 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2014-08-25 04:28:06 -0400 |
commit | 41c4a46423c08274ef83cdbd44bbd2066cba59bb (patch) | |
tree | 8d85cc93440209b831a5faf46ba2619c89b0b8c4 | |
parent | 56c47754631b98624e844305709d6a296bde20d1 (diff) |
HID: uhid: avoid dangling pointers in uhid context
Avoid keeping uhid->rd_data and uhid->rd_size set in case
uhid_dev_create2() fails. This is non-critical as we never flip
uhid->running and thus never enter uhid_dev_destroy(). However, it's much
nicer for debugging if pointers are only set if they point to valid data.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r-- | drivers/hid/uhid.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index c05b544cf588..bf13746d1731 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c | |||
@@ -363,20 +363,24 @@ static int uhid_dev_create2(struct uhid_device *uhid, | |||
363 | const struct uhid_event *ev) | 363 | const struct uhid_event *ev) |
364 | { | 364 | { |
365 | struct hid_device *hid; | 365 | struct hid_device *hid; |
366 | size_t rd_size; | ||
367 | void *rd_data; | ||
366 | int ret; | 368 | int ret; |
367 | 369 | ||
368 | if (uhid->running) | 370 | if (uhid->running) |
369 | return -EALREADY; | 371 | return -EALREADY; |
370 | 372 | ||
371 | uhid->rd_size = ev->u.create2.rd_size; | 373 | rd_size = ev->u.create2.rd_size; |
372 | if (uhid->rd_size <= 0 || uhid->rd_size > HID_MAX_DESCRIPTOR_SIZE) | 374 | if (rd_size <= 0 || rd_size > HID_MAX_DESCRIPTOR_SIZE) |
373 | return -EINVAL; | 375 | return -EINVAL; |
374 | 376 | ||
375 | uhid->rd_data = kmemdup(ev->u.create2.rd_data, uhid->rd_size, | 377 | rd_data = kmemdup(ev->u.create2.rd_data, rd_size, GFP_KERNEL); |
376 | GFP_KERNEL); | 378 | if (!rd_data) |
377 | if (!uhid->rd_data) | ||
378 | return -ENOMEM; | 379 | return -ENOMEM; |
379 | 380 | ||
381 | uhid->rd_size = rd_size; | ||
382 | uhid->rd_data = rd_data; | ||
383 | |||
380 | hid = hid_allocate_device(); | 384 | hid = hid_allocate_device(); |
381 | if (IS_ERR(hid)) { | 385 | if (IS_ERR(hid)) { |
382 | ret = PTR_ERR(hid); | 386 | ret = PTR_ERR(hid); |
@@ -416,6 +420,8 @@ err_hid: | |||
416 | uhid->running = false; | 420 | uhid->running = false; |
417 | err_free: | 421 | err_free: |
418 | kfree(uhid->rd_data); | 422 | kfree(uhid->rd_data); |
423 | uhid->rd_data = NULL; | ||
424 | uhid->rd_size = 0; | ||
419 | return ret; | 425 | return ret; |
420 | } | 426 | } |
421 | 427 | ||