summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2024-07-09 22:37:25 +0200
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-08-02 16:44:22 +0200
commit52831d9bbc9aa029aed525dfbe61cb78c1db991c (patch)
tree844870d0d4ba3a1ce7298bbdfef4daa959a2ca51
parent4bb1e7d027413835b086aed35bc3f0713bc0f72b (diff)
downloadlinux-52831d9bbc9aa029aed525dfbe61cb78c1db991c.tar.gz
linux-52831d9bbc9aa029aed525dfbe61cb78c1db991c.tar.bz2
linux-52831d9bbc9aa029aed525dfbe61cb78c1db991c.zip
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 d1efe3c324ea ("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 <linux@weissschuh.net> Link: https://patch.msgid.link/20240709-acpi-sysfs-groups-v2-2-058ab0667fa8@weissschuh.net Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/device_sysfs.c30
-rw-r--r--include/acpi/acpi_bus.h1
2 files changed, 15 insertions, 16 deletions
diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c
index 95a19e3569c8..6e4858ea035f 100644
--- a/drivers/acpi/device_sysfs.c
+++ b/drivers/acpi/device_sysfs.c
@@ -439,23 +439,33 @@ static ssize_t description_show(struct device *dev,
char *buf)
{
struct acpi_device *acpi_dev = to_acpi_device(dev);
+ struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+ union acpi_object *str_obj;
+ acpi_status status;
int result;
- if (acpi_dev->pnp.str_obj == NULL)
- return 0;
+ status = acpi_evaluate_object_typed(acpi_dev->handle, "_STR",
+ NULL, &buffer,
+ ACPI_TYPE_BUFFER);
+ if (ACPI_FAILURE(status))
+ return -EIO;
+
+ str_obj = buffer.pointer;
/*
* The _STR object contains a Unicode identifier for a device.
* We need to convert to utf-8 so it can be displayed.
*/
result = utf16s_to_utf8s(
- (wchar_t *)acpi_dev->pnp.str_obj->buffer.pointer,
- acpi_dev->pnp.str_obj->buffer.length,
+ (wchar_t *)str_obj->buffer.pointer,
+ str_obj->buffer.length,
UTF16_LITTLE_ENDIAN, buf,
PAGE_SIZE - 1);
buf[result++] = '\n';
+ kfree(str_obj);
+
return result;
}
static DEVICE_ATTR_RO(description);
@@ -513,8 +523,6 @@ static DEVICE_ATTR_RO(status);
*/
int acpi_device_setup_files(struct acpi_device *dev)
{
- struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
- acpi_status status;
int result = 0;
/*
@@ -540,12 +548,6 @@ int acpi_device_setup_files(struct acpi_device *dev)
* If device has _STR, 'description' file is created
*/
if (acpi_has_method(dev->handle, "_STR")) {
- status = acpi_evaluate_object_typed(dev->handle, "_STR",
- NULL, &buffer,
- ACPI_TYPE_BUFFER);
- if (ACPI_FAILURE(status))
- buffer.pointer = NULL;
- dev->pnp.str_obj = buffer.pointer;
result = device_create_file(&dev->dev, &dev_attr_description);
if (result)
goto end;
@@ -618,10 +620,8 @@ void acpi_device_remove_files(struct acpi_device *dev)
/*
* If device has _STR, remove 'description' file
*/
- if (acpi_has_method(dev->handle, "_STR")) {
- kfree(dev->pnp.str_obj);
+ if (acpi_has_method(dev->handle, "_STR"))
device_remove_file(&dev->dev, &dev_attr_description);
- }
/*
* If device has _EJ0, remove 'eject' file.
*/
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 8db5bd382915..d0ec808e2c42 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -255,7 +255,6 @@ struct acpi_device_pnp {
struct list_head ids; /* _HID and _CIDs */
acpi_device_name device_name; /* Driver-determined */
acpi_device_class device_class; /* " */
- union acpi_object *str_obj; /* unicode string for _STR method */
};
#define acpi_device_bid(d) ((d)->pnp.bus_id)