@@ -439,23 +439,33 @@ static ssize_t description_show(struct device *dev,
439
439
char * buf )
440
440
{
441
441
struct acpi_device * acpi_dev = to_acpi_device (dev );
442
+ struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER , NULL };
443
+ union acpi_object * str_obj ;
444
+ acpi_status status ;
442
445
int result ;
443
446
444
- if (acpi_dev -> pnp .str_obj == NULL )
445
- return 0 ;
447
+ status = acpi_evaluate_object_typed (acpi_dev -> handle , "_STR" ,
448
+ NULL , & buffer ,
449
+ ACPI_TYPE_BUFFER );
450
+ if (ACPI_FAILURE (status ))
451
+ return - EIO ;
452
+
453
+ str_obj = buffer .pointer ;
446
454
447
455
/*
448
456
* The _STR object contains a Unicode identifier for a device.
449
457
* We need to convert to utf-8 so it can be displayed.
450
458
*/
451
459
result = utf16s_to_utf8s (
452
- (wchar_t * )acpi_dev -> pnp . str_obj -> buffer .pointer ,
453
- acpi_dev -> pnp . str_obj -> buffer .length ,
460
+ (wchar_t * )str_obj -> buffer .pointer ,
461
+ str_obj -> buffer .length ,
454
462
UTF16_LITTLE_ENDIAN , buf ,
455
463
PAGE_SIZE - 1 );
456
464
457
465
buf [result ++ ] = '\n' ;
458
466
467
+ kfree (str_obj );
468
+
459
469
return result ;
460
470
}
461
471
static DEVICE_ATTR_RO (description );
@@ -507,96 +517,97 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
507
517
}
508
518
static DEVICE_ATTR_RO (status );
509
519
510
- /**
511
- * acpi_device_setup_files - Create sysfs attributes of an ACPI device.
512
- * @dev: ACPI device object.
513
- */
514
- int acpi_device_setup_files (struct acpi_device * dev )
515
- {
516
- struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER , NULL };
517
- acpi_status status ;
518
- int result = 0 ;
520
+ static struct attribute * acpi_attrs [] = {
521
+ & dev_attr_path .attr ,
522
+ & dev_attr_hid .attr ,
523
+ & dev_attr_modalias .attr ,
524
+ & dev_attr_description .attr ,
525
+ & dev_attr_adr .attr ,
526
+ & dev_attr_uid .attr ,
527
+ & dev_attr_sun .attr ,
528
+ & dev_attr_hrv .attr ,
529
+ & dev_attr_status .attr ,
530
+ & dev_attr_eject .attr ,
531
+ & dev_attr_power_state .attr ,
532
+ & dev_attr_real_power_state .attr ,
533
+ NULL
534
+ };
519
535
536
+ static bool acpi_show_attr (struct acpi_device * dev , const struct device_attribute * attr )
537
+ {
520
538
/*
521
539
* Devices gotten from FADT don't have a "path" attribute
522
540
*/
523
- if (dev -> handle ) {
524
- result = device_create_file (& dev -> dev , & dev_attr_path );
525
- if (result )
526
- goto end ;
527
- }
541
+ if (attr == & dev_attr_path )
542
+ return dev -> handle ;
528
543
529
- if (!list_empty (& dev -> pnp .ids )) {
530
- result = device_create_file (& dev -> dev , & dev_attr_hid );
531
- if (result )
532
- goto end ;
544
+ if (attr == & dev_attr_hid || attr == & dev_attr_modalias )
545
+ return !list_empty (& dev -> pnp .ids );
533
546
534
- result = device_create_file (& dev -> dev , & dev_attr_modalias );
535
- if (result )
536
- goto end ;
537
- }
547
+ if (attr == & dev_attr_description )
548
+ return acpi_has_method (dev -> handle , "_STR" );
538
549
539
- /*
540
- * If device has _STR, 'description' file is created
541
- */
542
- if (acpi_has_method (dev -> handle , "_STR" )) {
543
- status = acpi_evaluate_object (dev -> handle , "_STR" ,
544
- NULL , & buffer );
545
- if (ACPI_FAILURE (status ))
546
- buffer .pointer = NULL ;
547
- dev -> pnp .str_obj = buffer .pointer ;
548
- result = device_create_file (& dev -> dev , & dev_attr_description );
549
- if (result )
550
- goto end ;
551
- }
550
+ if (attr == & dev_attr_adr )
551
+ return dev -> pnp .type .bus_address ;
552
552
553
- if (dev -> pnp .type .bus_address )
554
- result = device_create_file (& dev -> dev , & dev_attr_adr );
555
- if (acpi_device_uid (dev ))
556
- result = device_create_file (& dev -> dev , & dev_attr_uid );
553
+ if (attr == & dev_attr_uid )
554
+ return acpi_device_uid (dev );
557
555
558
- if (acpi_has_method (dev -> handle , "_SUN" )) {
559
- result = device_create_file (& dev -> dev , & dev_attr_sun );
560
- if (result )
561
- goto end ;
562
- }
556
+ if (attr == & dev_attr_sun )
557
+ return acpi_has_method (dev -> handle , "_SUN" );
563
558
564
- if (acpi_has_method (dev -> handle , "_HRV" )) {
565
- result = device_create_file (& dev -> dev , & dev_attr_hrv );
566
- if (result )
567
- goto end ;
568
- }
559
+ if (attr == & dev_attr_hrv )
560
+ return acpi_has_method (dev -> handle , "_HRV" );
569
561
570
- if (acpi_has_method (dev -> handle , "_STA" )) {
571
- result = device_create_file (& dev -> dev , & dev_attr_status );
572
- if (result )
573
- goto end ;
574
- }
562
+ if (attr == & dev_attr_status )
563
+ return acpi_has_method (dev -> handle , "_STA" );
575
564
576
565
/*
577
566
* If device has _EJ0, 'eject' file is created that is used to trigger
578
567
* hot-removal function from userland.
579
568
*/
580
- if (acpi_has_method (dev -> handle , "_EJ0" )) {
581
- result = device_create_file (& dev -> dev , & dev_attr_eject );
582
- if (result )
583
- return result ;
584
- }
569
+ if (attr == & dev_attr_eject )
570
+ return acpi_has_method (dev -> handle , "_EJ0" );
585
571
586
- if (dev -> flags .power_manageable ) {
587
- result = device_create_file (& dev -> dev , & dev_attr_power_state );
588
- if (result )
589
- return result ;
572
+ if (attr == & dev_attr_power_state )
573
+ return dev -> flags .power_manageable ;
590
574
591
- if (dev -> power .flags .power_resources )
592
- result = device_create_file (& dev -> dev ,
593
- & dev_attr_real_power_state );
594
- }
575
+ if (attr == & dev_attr_real_power_state )
576
+ return dev -> flags .power_manageable && dev -> power .flags .power_resources ;
595
577
596
- acpi_expose_nondev_subnodes (& dev -> dev .kobj , & dev -> data );
578
+ dev_warn_once (& dev -> dev , "Unexpected attribute: %s\n" , attr -> attr .name );
579
+ return false;
580
+ }
597
581
598
- end :
599
- return result ;
582
+ static umode_t acpi_attr_is_visible (struct kobject * kobj ,
583
+ struct attribute * attr ,
584
+ int attrno )
585
+ {
586
+ struct acpi_device * dev = to_acpi_device (kobj_to_dev (kobj ));
587
+
588
+ if (acpi_show_attr (dev , container_of (attr , struct device_attribute , attr )))
589
+ return attr -> mode ;
590
+ else
591
+ return 0 ;
592
+ }
593
+
594
+ static const struct attribute_group acpi_group = {
595
+ .attrs = acpi_attrs ,
596
+ .is_visible = acpi_attr_is_visible ,
597
+ };
598
+
599
+ const struct attribute_group * acpi_groups [] = {
600
+ & acpi_group ,
601
+ NULL
602
+ };
603
+
604
+ /**
605
+ * acpi_device_setup_files - Create sysfs attributes of an ACPI device.
606
+ * @dev: ACPI device object.
607
+ */
608
+ void acpi_device_setup_files (struct acpi_device * dev )
609
+ {
610
+ acpi_expose_nondev_subnodes (& dev -> dev .kobj , & dev -> data );
600
611
}
601
612
602
613
/**
@@ -606,41 +617,4 @@ int acpi_device_setup_files(struct acpi_device *dev)
606
617
void acpi_device_remove_files (struct acpi_device * dev )
607
618
{
608
619
acpi_hide_nondev_subnodes (& dev -> data );
609
-
610
- if (dev -> flags .power_manageable ) {
611
- device_remove_file (& dev -> dev , & dev_attr_power_state );
612
- if (dev -> power .flags .power_resources )
613
- device_remove_file (& dev -> dev ,
614
- & dev_attr_real_power_state );
615
- }
616
-
617
- /*
618
- * If device has _STR, remove 'description' file
619
- */
620
- if (acpi_has_method (dev -> handle , "_STR" )) {
621
- kfree (dev -> pnp .str_obj );
622
- device_remove_file (& dev -> dev , & dev_attr_description );
623
- }
624
- /*
625
- * If device has _EJ0, remove 'eject' file.
626
- */
627
- if (acpi_has_method (dev -> handle , "_EJ0" ))
628
- device_remove_file (& dev -> dev , & dev_attr_eject );
629
-
630
- if (acpi_has_method (dev -> handle , "_SUN" ))
631
- device_remove_file (& dev -> dev , & dev_attr_sun );
632
-
633
- if (acpi_has_method (dev -> handle , "_HRV" ))
634
- device_remove_file (& dev -> dev , & dev_attr_hrv );
635
-
636
- if (acpi_device_uid (dev ))
637
- device_remove_file (& dev -> dev , & dev_attr_uid );
638
- if (dev -> pnp .type .bus_address )
639
- device_remove_file (& dev -> dev , & dev_attr_adr );
640
- device_remove_file (& dev -> dev , & dev_attr_modalias );
641
- device_remove_file (& dev -> dev , & dev_attr_hid );
642
- if (acpi_has_method (dev -> handle , "_STA" ))
643
- device_remove_file (& dev -> dev , & dev_attr_status );
644
- if (dev -> handle )
645
- device_remove_file (& dev -> dev , & dev_attr_path );
646
620
}
0 commit comments