Skip to content

Commit 52831d9

Browse files
t-8chrafaeljw
authored andcommitted
ACPI: sysfs: evaluate _STR on each sysfs access
The handling of the _STR method is inconsistent with the other method evaluations. It is the only method which is cached. The cached value stored in 'struct acpi_device_pnp' has a different lifetime than the other struct members. Commit d1efe3c ("ACPI: Add new sysfs interface to export device description") does not explain this difference. Evaluating the method every time also removes the necessity to manage the lifetime of the cached value, which would be a problem when managing the sysfs attributes through the device core. Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 4bb1e7d commit 52831d9

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

drivers/acpi/device_sysfs.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -439,23 +439,33 @@ static ssize_t description_show(struct device *dev,
439439
char *buf)
440440
{
441441
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;
442445
int result;
443446

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;
446454

447455
/*
448456
* The _STR object contains a Unicode identifier for a device.
449457
* We need to convert to utf-8 so it can be displayed.
450458
*/
451459
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,
454462
UTF16_LITTLE_ENDIAN, buf,
455463
PAGE_SIZE - 1);
456464

457465
buf[result++] = '\n';
458466

467+
kfree(str_obj);
468+
459469
return result;
460470
}
461471
static DEVICE_ATTR_RO(description);
@@ -513,8 +523,6 @@ static DEVICE_ATTR_RO(status);
513523
*/
514524
int acpi_device_setup_files(struct acpi_device *dev)
515525
{
516-
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
517-
acpi_status status;
518526
int result = 0;
519527

520528
/*
@@ -540,12 +548,6 @@ int acpi_device_setup_files(struct acpi_device *dev)
540548
* If device has _STR, 'description' file is created
541549
*/
542550
if (acpi_has_method(dev->handle, "_STR")) {
543-
status = acpi_evaluate_object_typed(dev->handle, "_STR",
544-
NULL, &buffer,
545-
ACPI_TYPE_BUFFER);
546-
if (ACPI_FAILURE(status))
547-
buffer.pointer = NULL;
548-
dev->pnp.str_obj = buffer.pointer;
549551
result = device_create_file(&dev->dev, &dev_attr_description);
550552
if (result)
551553
goto end;
@@ -618,10 +620,8 @@ void acpi_device_remove_files(struct acpi_device *dev)
618620
/*
619621
* If device has _STR, remove 'description' file
620622
*/
621-
if (acpi_has_method(dev->handle, "_STR")) {
622-
kfree(dev->pnp.str_obj);
623+
if (acpi_has_method(dev->handle, "_STR"))
623624
device_remove_file(&dev->dev, &dev_attr_description);
624-
}
625625
/*
626626
* If device has _EJ0, remove 'eject' file.
627627
*/

include/acpi/acpi_bus.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ struct acpi_device_pnp {
255255
struct list_head ids; /* _HID and _CIDs */
256256
acpi_device_name device_name; /* Driver-determined */
257257
acpi_device_class device_class; /* " */
258-
union acpi_object *str_obj; /* unicode string for _STR method */
259258
};
260259

261260
#define acpi_device_bid(d) ((d)->pnp.bus_id)

0 commit comments

Comments
 (0)