aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-07-29 11:14:16 -0400
committerJiri Kosina <jkosina@suse.cz>2014-08-25 04:28:05 -0400
commit56c47754631b98624e844305709d6a296bde20d1 (patch)
treefe555a648df69f9f26b3a12bb2a8d2ad045512e3
parent0e0d7520064c9f5668c030afafdbcab242176195 (diff)
HID: uhid: forward create_req to create2_req
Instead of hard-coding the uhid_dev_create() function twice, copy any create_req into a create2_req structure and forward it. We allocate uhid_create_req on the stack here, but that should be fine. Unlike uhid_create2_req it is fairly small (<1KB) and it's only used temporarily to swap entries. uhid_dev_create2() doesn't access it. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/uhid.c90
1 files changed, 25 insertions, 65 deletions
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index 16af4d382391..c05b544cf588 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -359,71 +359,6 @@ static int uhid_event_from_user(const char __user *buffer, size_t len,
359} 359}
360#endif 360#endif
361 361
362static int uhid_dev_create(struct uhid_device *uhid,
363 const struct uhid_event *ev)
364{
365 struct hid_device *hid;
366 int ret;
367
368 if (uhid->running)
369 return -EALREADY;
370
371 uhid->rd_size = ev->u.create.rd_size;
372 if (uhid->rd_size <= 0 || uhid->rd_size > HID_MAX_DESCRIPTOR_SIZE)
373 return -EINVAL;
374
375 uhid->rd_data = kmalloc(uhid->rd_size, GFP_KERNEL);
376 if (!uhid->rd_data)
377 return -ENOMEM;
378
379 if (copy_from_user(uhid->rd_data, ev->u.create.rd_data,
380 uhid->rd_size)) {
381 ret = -EFAULT;
382 goto err_free;
383 }
384
385 hid = hid_allocate_device();
386 if (IS_ERR(hid)) {
387 ret = PTR_ERR(hid);
388 goto err_free;
389 }
390
391 strncpy(hid->name, ev->u.create.name, 127);
392 hid->name[127] = 0;
393 strncpy(hid->phys, ev->u.create.phys, 63);
394 hid->phys[63] = 0;
395 strncpy(hid->uniq, ev->u.create.uniq, 63);
396 hid->uniq[63] = 0;
397
398 hid->ll_driver = &uhid_hid_driver;
399 hid->bus = ev->u.create.bus;
400 hid->vendor = ev->u.create.vendor;
401 hid->product = ev->u.create.product;
402 hid->version = ev->u.create.version;
403 hid->country = ev->u.create.country;
404 hid->driver_data = uhid;
405 hid->dev.parent = uhid_misc.this_device;
406
407 uhid->hid = hid;
408 uhid->running = true;
409
410 ret = hid_add_device(hid);
411 if (ret) {
412 hid_err(hid, "Cannot register HID device\n");
413 goto err_hid;
414 }
415
416 return 0;
417
418err_hid:
419 hid_destroy_device(hid);
420 uhid->hid = NULL;
421 uhid->running = false;
422err_free:
423 kfree(uhid->rd_data);
424 return ret;
425}
426
427static int uhid_dev_create2(struct uhid_device *uhid, 362static int uhid_dev_create2(struct uhid_device *uhid,
428 const struct uhid_event *ev) 363 const struct uhid_event *ev)
429{ 364{
@@ -484,6 +419,31 @@ err_free:
484 return ret; 419 return ret;
485} 420}
486 421
422static int uhid_dev_create(struct uhid_device *uhid,
423 struct uhid_event *ev)
424{
425 struct uhid_create_req orig;
426
427 orig = ev->u.create;
428
429 if (orig.rd_size <= 0 || orig.rd_size > HID_MAX_DESCRIPTOR_SIZE)
430 return -EINVAL;
431 if (copy_from_user(&ev->u.create2.rd_data, orig.rd_data, orig.rd_size))
432 return -EFAULT;
433
434 memcpy(ev->u.create2.name, orig.name, sizeof(orig.name));
435 memcpy(ev->u.create2.phys, orig.phys, sizeof(orig.phys));
436 memcpy(ev->u.create2.uniq, orig.uniq, sizeof(orig.uniq));
437 ev->u.create2.rd_size = orig.rd_size;
438 ev->u.create2.bus = orig.bus;
439 ev->u.create2.vendor = orig.vendor;
440 ev->u.create2.product = orig.product;
441 ev->u.create2.version = orig.version;
442 ev->u.create2.country = orig.country;
443
444 return uhid_dev_create2(uhid, ev);
445}
446
487static int uhid_dev_destroy(struct uhid_device *uhid) 447static int uhid_dev_destroy(struct uhid_device *uhid)
488{ 448{
489 if (!uhid->running) 449 if (!uhid->running)