Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] input core: remove custom-made hotplug handler

Input: remove custom-made hotplug handler

Now that all input devices are registered with sysfs we can remove
old custom-made hotplug handler and crate a standard one.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Dmitry Torokhov and committed by
Greg Kroah-Hartman
a7fadbe1 c9bcd582

+104 -145
+104 -145
drivers/input/input.c
··· 316 316 return NULL; 317 317 } 318 318 319 - 320 - /* 321 - * Input hotplugging interface - loading event handlers based on 322 - * device bitfields. 323 - */ 324 - 325 - #ifdef CONFIG_HOTPLUG 326 - 327 - /* 328 - * Input hotplugging invokes what /proc/sys/kernel/hotplug says 329 - * (normally /sbin/hotplug) when input devices get added or removed. 330 - * 331 - * This invokes a user mode policy agent, typically helping to load driver 332 - * or other modules, configure the device, and more. Drivers can provide 333 - * a MODULE_DEVICE_TABLE to help with module loading subtasks. 334 - * 335 - */ 336 - 337 - #define SPRINTF_BIT_A(bit, name, max) \ 338 - do { \ 339 - envp[i++] = scratch; \ 340 - scratch += sprintf(scratch, name); \ 341 - for (j = NBITS(max) - 1; j >= 0; j--) \ 342 - if (dev->bit[j]) break; \ 343 - for (; j >= 0; j--) \ 344 - scratch += sprintf(scratch, "%lx ", dev->bit[j]); \ 345 - scratch++; \ 346 - } while (0) 347 - 348 - #define SPRINTF_BIT_A2(bit, name, max, ev) \ 349 - do { \ 350 - if (test_bit(ev, dev->evbit)) \ 351 - SPRINTF_BIT_A(bit, name, max); \ 352 - } while (0) 353 - 354 - static void input_call_hotplug(char *verb, struct input_dev *dev) 355 - { 356 - char *argv[3], **envp, *buf, *scratch; 357 - int i = 0, j, value; 358 - 359 - if (!hotplug_path[0]) { 360 - printk(KERN_ERR "input.c: calling hotplug without a hotplug agent defined\n"); 361 - return; 362 - } 363 - if (in_interrupt()) { 364 - printk(KERN_ERR "input.c: calling hotplug from interrupt\n"); 365 - return; 366 - } 367 - if (!current->fs->root) { 368 - printk(KERN_WARNING "input.c: calling hotplug without valid filesystem\n"); 369 - return; 370 - } 371 - if (!(envp = (char **) kmalloc(20 * sizeof(char *), GFP_KERNEL))) { 372 - printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n"); 373 - return; 374 - } 375 - if (!(buf = kmalloc(1024, GFP_KERNEL))) { 376 - kfree (envp); 377 - printk(KERN_ERR "input.c: not enough memory allocating hotplug environment\n"); 378 - return; 379 - } 380 - 381 - argv[0] = hotplug_path; 382 - argv[1] = "input"; 383 - argv[2] = NULL; 384 - 385 - envp[i++] = "HOME=/"; 386 - envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; 387 - 388 - scratch = buf; 389 - 390 - envp[i++] = scratch; 391 - scratch += sprintf(scratch, "ACTION=%s", verb) + 1; 392 - 393 - envp[i++] = scratch; 394 - scratch += sprintf(scratch, "PRODUCT=%x/%x/%x/%x", 395 - dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) + 1; 396 - 397 - if (dev->name) { 398 - envp[i++] = scratch; 399 - scratch += sprintf(scratch, "NAME=%s", dev->name) + 1; 400 - } 401 - 402 - if (dev->phys) { 403 - envp[i++] = scratch; 404 - scratch += sprintf(scratch, "PHYS=%s", dev->phys) + 1; 405 - } 406 - 407 - SPRINTF_BIT_A(evbit, "EV=", EV_MAX); 408 - SPRINTF_BIT_A2(keybit, "KEY=", KEY_MAX, EV_KEY); 409 - SPRINTF_BIT_A2(relbit, "REL=", REL_MAX, EV_REL); 410 - SPRINTF_BIT_A2(absbit, "ABS=", ABS_MAX, EV_ABS); 411 - SPRINTF_BIT_A2(mscbit, "MSC=", MSC_MAX, EV_MSC); 412 - SPRINTF_BIT_A2(ledbit, "LED=", LED_MAX, EV_LED); 413 - SPRINTF_BIT_A2(sndbit, "SND=", SND_MAX, EV_SND); 414 - SPRINTF_BIT_A2(ffbit, "FF=", FF_MAX, EV_FF); 415 - SPRINTF_BIT_A2(swbit, "SW=", SW_MAX, EV_SW); 416 - 417 - envp[i++] = NULL; 418 - 419 - #ifdef INPUT_DEBUG 420 - printk(KERN_DEBUG "input.c: calling %s %s [%s %s %s %s %s]\n", 421 - argv[0], argv[1], envp[0], envp[1], envp[2], envp[3], envp[4]); 422 - #endif 423 - 424 - value = call_usermodehelper(argv [0], argv, envp, 0); 425 - 426 - kfree(buf); 427 - kfree(envp); 428 - 429 - #ifdef INPUT_DEBUG 430 - if (value != 0) 431 - printk(KERN_DEBUG "input.c: hotplug returned %d\n", value); 432 - #endif 433 - } 434 - 435 - #endif 436 - 437 - static int input_print_bitmap(char *buf, unsigned long *bitmap, int max) 319 + static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap, int max) 438 320 { 439 321 int i; 440 322 int len = 0; ··· 326 444 break; 327 445 328 446 for (; i >= 0; i--) 329 - len += sprintf(buf + len, "%lx%s", bitmap[i], i > 0 ? " " : ""); 330 - 331 - len += sprintf(buf + len, "\n"); 332 - 447 + len += snprintf(buf + len, max(buf_size - len, 0), 448 + "%lx%s", bitmap[i], i > 0 ? " " : ""); 333 449 return len; 334 450 } 335 451 ··· 352 472 return 0; 353 473 } 354 474 355 - #define SPRINTF_BIT_B(ev, bm) \ 475 + #define SPRINTF_BIT(ev, bm) \ 356 476 do { \ 357 477 len += sprintf(buf + len, "B: %s=", #ev); \ 358 - len += input_print_bitmap(buf + len, \ 478 + len += input_print_bitmap(buf + len, INT_MAX, \ 359 479 dev->bm##bit, ev##_MAX); \ 480 + len += sprintf(buf + len, "\n"); \ 360 481 } while (0) 361 482 362 - #define SPRINTF_BIT_B2(ev, bm) \ 483 + #define TEST_AND_SPRINTF_BIT(ev, bm) \ 363 484 do { \ 364 485 if (test_bit(EV_##ev, dev->evbit)) \ 365 - SPRINTF_BIT_B(ev, bm); \ 486 + SPRINTF_BIT(ev, bm); \ 366 487 } while (0) 367 488 368 489 static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data) ··· 392 511 393 512 len += sprintf(buf + len, "\n"); 394 513 395 - SPRINTF_BIT_B(EV, ev); 396 - SPRINTF_BIT_B2(KEY, key); 397 - SPRINTF_BIT_B2(REL, rel); 398 - SPRINTF_BIT_B2(ABS, abs); 399 - SPRINTF_BIT_B2(MSC, msc); 400 - SPRINTF_BIT_B2(LED, led); 401 - SPRINTF_BIT_B2(SND, snd); 402 - SPRINTF_BIT_B2(FF, ff); 403 - SPRINTF_BIT_B2(SW, sw); 514 + SPRINTF_BIT(EV, ev); 515 + TEST_AND_SPRINTF_BIT(KEY, key); 516 + TEST_AND_SPRINTF_BIT(REL, rel); 517 + TEST_AND_SPRINTF_BIT(ABS, abs); 518 + TEST_AND_SPRINTF_BIT(MSC, msc); 519 + TEST_AND_SPRINTF_BIT(LED, led); 520 + TEST_AND_SPRINTF_BIT(SND, snd); 521 + TEST_AND_SPRINTF_BIT(FF, ff); 522 + TEST_AND_SPRINTF_BIT(SW, sw); 404 523 405 524 len += sprintf(buf + len, "\n"); 406 525 ··· 570 689 static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \ 571 690 { \ 572 691 struct input_dev *input_dev = to_input_dev(dev); \ 573 - return input_print_bitmap(buf, input_dev->bm##bit, ev##_MAX); \ 692 + return input_print_bitmap(buf, PAGE_SIZE, input_dev->bm##bit, ev##_MAX);\ 574 693 } \ 575 694 static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL); 576 695 ··· 610 729 module_put(THIS_MODULE); 611 730 } 612 731 732 + /* 733 + * Input hotplugging interface - loading event handlers based on 734 + * device bitfields. 735 + */ 736 + static int input_add_hotplug_bm_var(char **envp, int num_envp, int *cur_index, 737 + char *buffer, int buffer_size, int *cur_len, 738 + const char *name, unsigned long *bitmap, int max) 739 + { 740 + if (*cur_index >= num_envp - 1) 741 + return -ENOMEM; 742 + 743 + envp[*cur_index] = buffer + *cur_len; 744 + 745 + *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name); 746 + if (*cur_len > buffer_size) 747 + return -ENOMEM; 748 + 749 + *cur_len += input_print_bitmap(buffer + *cur_len, 750 + max(buffer_size - *cur_len, 0), 751 + bitmap, max) + 1; 752 + if (*cur_len > buffer_size) 753 + return -ENOMEM; 754 + 755 + (*cur_index)++; 756 + return 0; 757 + } 758 + 759 + #define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \ 760 + do { \ 761 + int err = add_hotplug_env_var(envp, num_envp, &i, \ 762 + buffer, buffer_size, &len, \ 763 + fmt, val); \ 764 + if (err) \ 765 + return err; \ 766 + } while (0) 767 + 768 + #define INPUT_ADD_HOTPLUG_BM_VAR(name, bm, max) \ 769 + do { \ 770 + int err = input_add_hotplug_bm_var(envp, num_envp, &i, \ 771 + buffer, buffer_size, &len, \ 772 + name, bm, max); \ 773 + if (err) \ 774 + return err; \ 775 + } while (0) 776 + 777 + static int input_dev_hotplug(struct class_device *cdev, char **envp, 778 + int num_envp, char *buffer, int buffer_size) 779 + { 780 + struct input_dev *dev = to_input_dev(cdev); 781 + int i = 0; 782 + int len = 0; 783 + 784 + INPUT_ADD_HOTPLUG_VAR("PRODUCT=%x/%x/%x/%x", 785 + dev->id.bustype, dev->id.vendor, 786 + dev->id.product, dev->id.version); 787 + if (dev->name) 788 + INPUT_ADD_HOTPLUG_VAR("NAME=\"%s\"", dev->name); 789 + if (dev->phys) 790 + INPUT_ADD_HOTPLUG_VAR("PHYS=\"%s\"", dev->phys); 791 + if (dev->phys) 792 + INPUT_ADD_HOTPLUG_VAR("UNIQ=\"%s\"", dev->uniq); 793 + 794 + INPUT_ADD_HOTPLUG_BM_VAR("EV=", dev->evbit, EV_MAX); 795 + if (test_bit(EV_KEY, dev->evbit)) 796 + INPUT_ADD_HOTPLUG_BM_VAR("KEY=", dev->keybit, KEY_MAX); 797 + if (test_bit(EV_REL, dev->evbit)) 798 + INPUT_ADD_HOTPLUG_BM_VAR("REL=", dev->relbit, REL_MAX); 799 + if (test_bit(EV_ABS, dev->evbit)) 800 + INPUT_ADD_HOTPLUG_BM_VAR("ABS=", dev->absbit, ABS_MAX); 801 + if (test_bit(EV_MSC, dev->evbit)) 802 + INPUT_ADD_HOTPLUG_BM_VAR("MSC=", dev->mscbit, MSC_MAX); 803 + if (test_bit(EV_LED, dev->evbit)) 804 + INPUT_ADD_HOTPLUG_BM_VAR("LED=", dev->ledbit, LED_MAX); 805 + if (test_bit(EV_SND, dev->evbit)) 806 + INPUT_ADD_HOTPLUG_BM_VAR("SND=", dev->sndbit, SND_MAX); 807 + if (test_bit(EV_FF, dev->evbit)) 808 + INPUT_ADD_HOTPLUG_BM_VAR("FF=", dev->ffbit, FF_MAX); 809 + if (test_bit(EV_SW, dev->evbit)) 810 + INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); 811 + 812 + envp[i] = NULL; 813 + 814 + return 0; 815 + } 816 + 613 817 struct class input_class = { 614 818 .name = "input", 615 819 .release = input_dev_release, 820 + .hotplug = input_dev_hotplug, 616 821 }; 617 822 618 823 struct input_dev *input_allocate_device(void) ··· 777 810 input_link_handle(handle); 778 811 779 812 780 - #ifdef CONFIG_HOTPLUG 781 - input_call_hotplug("add", dev); 782 - #endif 783 - 784 813 input_wakeup_procfs_readers(); 785 814 } 786 815 ··· 794 831 list_del_init(&handle->h_node); 795 832 handle->handler->disconnect(handle); 796 833 } 797 - 798 - #ifdef CONFIG_HOTPLUG 799 - input_call_hotplug("remove", dev); 800 - #endif 801 834 802 835 list_del_init(&dev->node); 803 836