@@ -572,6 +572,34 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
572
572
}
573
573
EXPORT_SYMBOL (rfkill_set_states );
574
574
575
+ static const char * const rfkill_types [] = {
576
+ NULL , /* RFKILL_TYPE_ALL */
577
+ "wlan" ,
578
+ "bluetooth" ,
579
+ "ultrawideband" ,
580
+ "wimax" ,
581
+ "wwan" ,
582
+ "gps" ,
583
+ "fm" ,
584
+ "nfc" ,
585
+ };
586
+
587
+ enum rfkill_type rfkill_find_type (const char * name )
588
+ {
589
+ int i ;
590
+
591
+ BUILD_BUG_ON (ARRAY_SIZE (rfkill_types ) != NUM_RFKILL_TYPES );
592
+
593
+ if (!name )
594
+ return RFKILL_TYPE_ALL ;
595
+
596
+ for (i = 1 ; i < NUM_RFKILL_TYPES ; i ++ )
597
+ if (!strcmp (name , rfkill_types [i ]))
598
+ return i ;
599
+ return RFKILL_TYPE_ALL ;
600
+ }
601
+ EXPORT_SYMBOL (rfkill_find_type );
602
+
575
603
static ssize_t name_show (struct device * dev , struct device_attribute * attr ,
576
604
char * buf )
577
605
{
@@ -581,38 +609,12 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
581
609
}
582
610
static DEVICE_ATTR_RO (name );
583
611
584
- static const char * rfkill_get_type_str (enum rfkill_type type )
585
- {
586
- BUILD_BUG_ON (NUM_RFKILL_TYPES != RFKILL_TYPE_NFC + 1 );
587
-
588
- switch (type ) {
589
- case RFKILL_TYPE_WLAN :
590
- return "wlan" ;
591
- case RFKILL_TYPE_BLUETOOTH :
592
- return "bluetooth" ;
593
- case RFKILL_TYPE_UWB :
594
- return "ultrawideband" ;
595
- case RFKILL_TYPE_WIMAX :
596
- return "wimax" ;
597
- case RFKILL_TYPE_WWAN :
598
- return "wwan" ;
599
- case RFKILL_TYPE_GPS :
600
- return "gps" ;
601
- case RFKILL_TYPE_FM :
602
- return "fm" ;
603
- case RFKILL_TYPE_NFC :
604
- return "nfc" ;
605
- default :
606
- BUG ();
607
- }
608
- }
609
-
610
612
static ssize_t type_show (struct device * dev , struct device_attribute * attr ,
611
613
char * buf )
612
614
{
613
615
struct rfkill * rfkill = to_rfkill (dev );
614
616
615
- return sprintf (buf , "%s\n" , rfkill_get_type_str ( rfkill -> type ) );
617
+ return sprintf (buf , "%s\n" , rfkill_types [ rfkill -> type ] );
616
618
}
617
619
static DEVICE_ATTR_RO (type );
618
620
@@ -750,7 +752,7 @@ static int rfkill_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
750
752
if (error )
751
753
return error ;
752
754
error = add_uevent_var (env , "RFKILL_TYPE=%s" ,
753
- rfkill_get_type_str ( rfkill -> type ) );
755
+ rfkill_types [ rfkill -> type ] );
754
756
if (error )
755
757
return error ;
756
758
spin_lock_irqsave (& rfkill -> lock , flags );
0 commit comments