Simplify the lifecycle of the sysfs attributes by letting the device core manage them.
Signed-off-by: Thomas Weißschuh linux@weissschuh.net --- Changes in v2: - Add fix to validate buffer type validation (patch 1) - Drop usage of devm-APIs as these are unusable for unbound devices - Evaluate _STR on each sysfs access - Link to v1: https://lore.kernel.org/r/20240613-acpi-sysfs-groups-v1-0-665e0deb052a@weiss...
--- Thomas Weißschuh (5): ACPI: sysfs: validate return type of _STR method ACPI: sysfs: evaluate _STR on each sysfs access ACPI: sysfs: manage attributes as attribute_group ACPI: sysfs: manage sysfs attributes through device core ACPI: sysfs: remove return value of acpi_device_setup_files()
drivers/acpi/device_sysfs.c | 196 +++++++++++++++++++------------------------- drivers/acpi/internal.h | 3 +- drivers/acpi/scan.c | 6 +- include/acpi/acpi_bus.h | 1 - 4 files changed, 89 insertions(+), 117 deletions(-) --- base-commit: 34afb82a3c67f869267a26f593b6f8fc6bf35905 change-id: 20240609-acpi-sysfs-groups-cfa756d16752
Best regards,
Only buffer objects are valid return values of _STR. If something else is returned description_show() will access invalid memory.
Fixes: d1efe3c324ea ("ACPI: Add new sysfs interface to export device description") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh linux@weissschuh.net --- drivers/acpi/device_sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 23373faa35ec..95a19e3569c8 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -540,8 +540,9 @@ 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(dev->handle, "_STR", - NULL, &buffer); + 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;
On Tue, Jul 9, 2024 at 10:38 PM Thomas Weißschuh linux@weissschuh.net wrote:
Simplify the lifecycle of the sysfs attributes by letting the device core manage them.
Signed-off-by: Thomas Weißschuh linux@weissschuh.net
Changes in v2:
- Add fix to validate buffer type validation (patch 1)
- Drop usage of devm-APIs as these are unusable for unbound devices
- Evaluate _STR on each sysfs access
- Link to v1: https://lore.kernel.org/r/20240613-acpi-sysfs-groups-v1-0-665e0deb052a@weiss...
Thomas Weißschuh (5): ACPI: sysfs: validate return type of _STR method ACPI: sysfs: evaluate _STR on each sysfs access ACPI: sysfs: manage attributes as attribute_group ACPI: sysfs: manage sysfs attributes through device core ACPI: sysfs: remove return value of acpi_device_setup_files()
drivers/acpi/device_sysfs.c | 196 +++++++++++++++++++------------------------- drivers/acpi/internal.h | 3 +- drivers/acpi/scan.c | 6 +- include/acpi/acpi_bus.h | 1 - 4 files changed, 89 insertions(+), 117 deletions(-)
If this is not urgent, and I don't think it is, I'd rather defer it to the 6.12 cycle (that is, I'd apply it after the upcoming 6.11 merge window).
Thanks!
On 2024-07-10 13:43:57+0000, Rafael J. Wysocki wrote:
On Tue, Jul 9, 2024 at 10:38 PM Thomas Weißschuh linux@weissschuh.net wrote:
Simplify the lifecycle of the sysfs attributes by letting the device core manage them.
Signed-off-by: Thomas Weißschuh linux@weissschuh.net
Changes in v2:
- Add fix to validate buffer type validation (patch 1)
- Drop usage of devm-APIs as these are unusable for unbound devices
- Evaluate _STR on each sysfs access
- Link to v1: https://lore.kernel.org/r/20240613-acpi-sysfs-groups-v1-0-665e0deb052a@weiss...
Thomas Weißschuh (5): ACPI: sysfs: validate return type of _STR method ACPI: sysfs: evaluate _STR on each sysfs access ACPI: sysfs: manage attributes as attribute_group ACPI: sysfs: manage sysfs attributes through device core ACPI: sysfs: remove return value of acpi_device_setup_files()
drivers/acpi/device_sysfs.c | 196 +++++++++++++++++++------------------------- drivers/acpi/internal.h | 3 +- drivers/acpi/scan.c | 6 +- include/acpi/acpi_bus.h | 1 - 4 files changed, 89 insertions(+), 117 deletions(-)
If this is not urgent, and I don't think it is, I'd rather defer it to the 6.12 cycle (that is, I'd apply it after the upcoming 6.11 merge window).
Sounds good to me.
Thanks, Thomas
linux-stable-mirror@lists.linaro.org