@@ -316,125 +316,7 @@ static struct input_device_id *input_match_device(struct input_device_id *id, st
316316 return NULL ;
317317}
318318
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 )
438320{
439321 int i ;
440322 int len = 0 ;
@@ -444,10 +326,8 @@ static int input_print_bitmap(char *buf, unsigned long *bitmap, int max)
444326 break ;
445327
446328 for (; i >= 0 ; i -- )
447- len += sprintf (buf + len , "%lx%s" , bitmap [i ], i > 0 ? " " : "" );
448-
449- len += sprintf (buf + len , "\n" );
450-
329+ len += snprintf (buf + len , max (buf_size - len , 0 ),
330+ "%lx%s" , bitmap [i ], i > 0 ? " " : "" );
451331 return len ;
452332}
453333
@@ -472,17 +352,18 @@ static unsigned int input_devices_poll(struct file *file, poll_table *wait)
472352 return 0 ;
473353}
474354
475- #define SPRINTF_BIT_B (ev , bm ) \
355+ #define SPRINTF_BIT (ev , bm ) \
476356 do { \
477357 len += sprintf(buf + len, "B: %s=", #ev); \
478- len += input_print_bitmap(buf + len, \
358+ len += input_print_bitmap(buf + len, INT_MAX, \
479359 dev->bm##bit, ev##_MAX); \
360+ len += sprintf(buf + len, "\n"); \
480361 } while (0)
481362
482- #define SPRINTF_BIT_B2 (ev , bm ) \
363+ #define TEST_AND_SPRINTF_BIT (ev , bm ) \
483364 do { \
484365 if (test_bit(EV_##ev, dev->evbit)) \
485- SPRINTF_BIT_B (ev, bm); \
366+ SPRINTF_BIT (ev, bm); \
486367 } while (0)
487368
488369static int input_devices_read (char * buf , char * * start , off_t pos , int count , int * eof , void * data )
@@ -511,15 +392,15 @@ static int input_devices_read(char *buf, char **start, off_t pos, int count, int
511392
512393 len += sprintf (buf + len , "\n" );
513394
514- SPRINTF_BIT_B (EV , ev );
515- SPRINTF_BIT_B2 (KEY , key );
516- SPRINTF_BIT_B2 (REL , rel );
517- SPRINTF_BIT_B2 (ABS , abs );
518- SPRINTF_BIT_B2 (MSC , msc );
519- SPRINTF_BIT_B2 (LED , led );
520- SPRINTF_BIT_B2 (SND , snd );
521- SPRINTF_BIT_B2 (FF , ff );
522- SPRINTF_BIT_B2 (SW , sw );
395+ SPRINTF_BIT (EV , ev );
396+ TEST_AND_SPRINTF_BIT (KEY , key );
397+ TEST_AND_SPRINTF_BIT (REL , rel );
398+ TEST_AND_SPRINTF_BIT (ABS , abs );
399+ TEST_AND_SPRINTF_BIT (MSC , msc );
400+ TEST_AND_SPRINTF_BIT (LED , led );
401+ TEST_AND_SPRINTF_BIT (SND , snd );
402+ TEST_AND_SPRINTF_BIT (FF , ff );
403+ TEST_AND_SPRINTF_BIT (SW , sw );
523404
524405 len += sprintf (buf + len , "\n" );
525406
@@ -689,7 +570,7 @@ static struct attribute_group input_dev_id_attr_group = {
689570static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \
690571{ \
691572 struct input_dev *input_dev = to_input_dev(dev); \
692- return input_print_bitmap(buf, input_dev->bm##bit, ev##_MAX); \
573+ return input_print_bitmap(buf, PAGE_SIZE, input_dev->bm##bit, ev##_MAX);\
693574} \
694575static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
695576
@@ -729,9 +610,95 @@ static void input_dev_release(struct class_device *class_dev)
729610 module_put (THIS_MODULE );
730611}
731612
613+ /*
614+ * Input hotplugging interface - loading event handlers based on
615+ * device bitfields.
616+ */
617+ static int input_add_hotplug_bm_var (char * * envp , int num_envp , int * cur_index ,
618+ char * buffer , int buffer_size , int * cur_len ,
619+ const char * name , unsigned long * bitmap , int max )
620+ {
621+ if (* cur_index >= num_envp - 1 )
622+ return - ENOMEM ;
623+
624+ envp [* cur_index ] = buffer + * cur_len ;
625+
626+ * cur_len += snprintf (buffer + * cur_len , max (buffer_size - * cur_len , 0 ), name );
627+ if (* cur_len > buffer_size )
628+ return - ENOMEM ;
629+
630+ * cur_len += input_print_bitmap (buffer + * cur_len ,
631+ max (buffer_size - * cur_len , 0 ),
632+ bitmap , max ) + 1 ;
633+ if (* cur_len > buffer_size )
634+ return - ENOMEM ;
635+
636+ (* cur_index )++ ;
637+ return 0 ;
638+ }
639+
640+ #define INPUT_ADD_HOTPLUG_VAR (fmt , val ...) \
641+ do { \
642+ int err = add_hotplug_env_var(envp, num_envp, &i, \
643+ buffer, buffer_size, &len, \
644+ fmt, val); \
645+ if (err) \
646+ return err; \
647+ } while (0)
648+
649+ #define INPUT_ADD_HOTPLUG_BM_VAR (name , bm , max ) \
650+ do { \
651+ int err = input_add_hotplug_bm_var(envp, num_envp, &i, \
652+ buffer, buffer_size, &len, \
653+ name, bm, max); \
654+ if (err) \
655+ return err; \
656+ } while (0)
657+
658+ static int input_dev_hotplug (struct class_device * cdev , char * * envp ,
659+ int num_envp , char * buffer , int buffer_size )
660+ {
661+ struct input_dev * dev = to_input_dev (cdev );
662+ int i = 0 ;
663+ int len = 0 ;
664+
665+ INPUT_ADD_HOTPLUG_VAR ("PRODUCT=%x/%x/%x/%x" ,
666+ dev -> id .bustype , dev -> id .vendor ,
667+ dev -> id .product , dev -> id .version );
668+ if (dev -> name )
669+ INPUT_ADD_HOTPLUG_VAR ("NAME=\"%s\"" , dev -> name );
670+ if (dev -> phys )
671+ INPUT_ADD_HOTPLUG_VAR ("PHYS=\"%s\"" , dev -> phys );
672+ if (dev -> phys )
673+ INPUT_ADD_HOTPLUG_VAR ("UNIQ=\"%s\"" , dev -> uniq );
674+
675+ INPUT_ADD_HOTPLUG_BM_VAR ("EV=" , dev -> evbit , EV_MAX );
676+ if (test_bit (EV_KEY , dev -> evbit ))
677+ INPUT_ADD_HOTPLUG_BM_VAR ("KEY=" , dev -> keybit , KEY_MAX );
678+ if (test_bit (EV_REL , dev -> evbit ))
679+ INPUT_ADD_HOTPLUG_BM_VAR ("REL=" , dev -> relbit , REL_MAX );
680+ if (test_bit (EV_ABS , dev -> evbit ))
681+ INPUT_ADD_HOTPLUG_BM_VAR ("ABS=" , dev -> absbit , ABS_MAX );
682+ if (test_bit (EV_MSC , dev -> evbit ))
683+ INPUT_ADD_HOTPLUG_BM_VAR ("MSC=" , dev -> mscbit , MSC_MAX );
684+ if (test_bit (EV_LED , dev -> evbit ))
685+ INPUT_ADD_HOTPLUG_BM_VAR ("LED=" , dev -> ledbit , LED_MAX );
686+ if (test_bit (EV_SND , dev -> evbit ))
687+ INPUT_ADD_HOTPLUG_BM_VAR ("SND=" , dev -> sndbit , SND_MAX );
688+ if (test_bit (EV_FF , dev -> evbit ))
689+ INPUT_ADD_HOTPLUG_BM_VAR ("FF=" , dev -> ffbit , FF_MAX );
690+ if (test_bit (EV_SW , dev -> evbit ))
691+ INPUT_ADD_HOTPLUG_BM_VAR ("SW=" , dev -> swbit , SW_MAX );
692+
693+ envp [i ] = NULL ;
694+
695+ return 0 ;
696+ }
697+
732698struct class input_class = {
733699 .name = "input" ,
734700 .release = input_dev_release ,
701+ .hotplug = input_dev_hotplug ,
735702};
736703
737704struct input_dev * input_allocate_device (void )
@@ -810,10 +777,6 @@ void input_register_device(struct input_dev *dev)
810777 input_link_handle (handle );
811778
812779
813- #ifdef CONFIG_HOTPLUG
814- input_call_hotplug ("add" , dev );
815- #endif
816-
817780 input_wakeup_procfs_readers ();
818781}
819782
@@ -832,10 +795,6 @@ void input_unregister_device(struct input_dev *dev)
832795 handle -> handler -> disconnect (handle );
833796 }
834797
835- #ifdef CONFIG_HOTPLUG
836- input_call_hotplug ("remove" , dev );
837- #endif
838-
839798 list_del_init (& dev -> node );
840799
841800 if (dev -> dynalloc ) {
0 commit comments