From nobody Wed Dec 17 13:56:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8268518002F; Tue, 9 Jul 2024 20:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; cv=none; b=HAXWhwzXQHdu1h+uIzSp5yUTlsvm88wh4G5Hg1h+IIweUK7DETzhmOSHS+XQdubXjoHujrQXPWkP1uuwqXyDbWvqKPe8Vq38FHCPK1dERiVORQig+rLdJirm1VuVihBqZZ6rH3J44CQOQ7oZrC9CnZyf6hWLemgnRRbBrnUlmi8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; c=relaxed/simple; bh=4LOKIwPkfG4qv/qDrlGxW3TsoLB+emhFXbvx4Ix4Zk0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rNDevLZDTxyCVlMBRc+WVet9mDFIz7dWoXC8Fs2qdFG7NyYi5PSmUZFbwFVKAVq21PIfuzIRiu6Lm/jLc4oguPniHFUpgt6J+P0i2ym/DNgCBUj+KsGlhrE0mGICBSE7kyUx62ANs57f5YYoi2hZvyYlUOHQshPzJXdIbiM+d3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=dG40KnSp; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="dG40KnSp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1720557499; bh=4LOKIwPkfG4qv/qDrlGxW3TsoLB+emhFXbvx4Ix4Zk0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dG40KnSpTErTVkKTdq6BRp9NadeBRzRCaWTosI7Tk4miaSgMU5DWQ3YDJ8flzqxSq pecskGFgWhodamgFdTf/PyATSfiuvRtjLyFek+lNzebuporQFrIS394sOKiD5BLjHq TFUj94mQn0Gy57ANFUBOofRKbY+sLaToTC3pffeE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 09 Jul 2024 22:37:24 +0200 Subject: [PATCH v2 1/5] ACPI: sysfs: validate return type of _STR method Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240709-acpi-sysfs-groups-v2-1-058ab0667fa8@weissschuh.net> References: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> In-Reply-To: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown , Robert Moore , Lance Ortiz Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , stable@vger.kernel.org X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720557498; l=1077; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=4LOKIwPkfG4qv/qDrlGxW3TsoLB+emhFXbvx4Ix4Zk0=; b=LEZeIImkrMhJWNTWnePl193SC5ykHqSmHMH0lFF8V6YtbXAs2SlU4XQBY/in1QpVwIYrpSUF/ OYbf6q9I5wgDzFFsRO4cyIZQSRalkUg/SuoRcoHipm/3rernkKkInU9 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= 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 descri= ption") Cc: stable@vger.kernel.org Signed-off-by: Thomas Wei=C3=9Fschuh --- 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 =3D acpi_evaluate_object(dev->handle, "_STR", - NULL, &buffer); + status =3D acpi_evaluate_object_typed(dev->handle, "_STR", + NULL, &buffer, + ACPI_TYPE_BUFFER); if (ACPI_FAILURE(status)) buffer.pointer =3D NULL; dev->pnp.str_obj =3D buffer.pointer; --=20 2.45.2 From nobody Wed Dec 17 13:56:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0854E182A63; Tue, 9 Jul 2024 20:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; cv=none; b=lrYTs0p0iIbeXLSqoZCZSy+vEbtHYrq/i7zv75E6SrToVlFekBuwzwYhEPU+R2gOuDJ5cbaF2Ycypt5aROeE1KCIAUAwZWZCqbxZu7VLl1DGQba7nqpruUilG7a1aJYsROZeQhHH+C0SC0oCUxcglcpAFxq4MX8oMcpEXgvzZ3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; c=relaxed/simple; bh=q+YR3m2EXR3uKtrR6shoZSOKk/iB5ADwRrDy+seaaEQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RdI9v04CL4M5pQurGOOZG0lZwVhwKtCiSpLekUTM5NOO/uSQ3MvRnUdQYz+yUysPEHcTx6KY2EadQ+kZKWbvmP5l6sJmuGtVf1x1bFfCkVsP6OeXf6DupJQzB9POERJRwIEXmeVuxwKiVvE3mddbwpZJG1jQ4VKySyINpvPkeDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=qfWbczE8; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="qfWbczE8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1720557499; bh=q+YR3m2EXR3uKtrR6shoZSOKk/iB5ADwRrDy+seaaEQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qfWbczE8oE+WdoghqQsFcmDhxA1S+IevXgD4lSBbviTSvN5aPm7TUDTzmhHjJL8zB n3cviZMHCb3yhI9D8mzR6Xw0NT+PbPCZxSc0SIufuedNs9eai2zRmWFlEi9uNxUF43 0UVhARZHMfMuM60/YIYKYKHh+uJ7xeBWZMZ6fqxs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 09 Jul 2024 22:37:25 +0200 Subject: [PATCH v2 2/5] ACPI: sysfs: evaluate _STR on each sysfs access Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240709-acpi-sysfs-groups-v2-2-058ab0667fa8@weissschuh.net> References: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> In-Reply-To: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown , Robert Moore , Lance Ortiz Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720557498; l=3611; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=q+YR3m2EXR3uKtrR6shoZSOKk/iB5ADwRrDy+seaaEQ=; b=Vjq2sGtbGSTufPTPJ/zrDOKpT1qfTVZdB3YFAJwuDNGNZB6wN+X2708Rb81QHw8LMyu2x9KY1 jJTFd0aZrEWCLFB8SMXIT4jEIaRRMc68xDwJV9AlMw7XI24ANCKLfSW X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= 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 descri= ption") 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=C3=9Fschuh --- drivers/acpi/device_sysfs.c | 30 +++++++++++++++--------------- include/acpi/acpi_bus.h | 1 - 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 =3D to_acpi_device(dev); + struct acpi_buffer buffer =3D {ACPI_ALLOCATE_BUFFER, NULL}; + union acpi_object *str_obj; + acpi_status status; int result; =20 - if (acpi_dev->pnp.str_obj =3D=3D NULL) - return 0; + status =3D acpi_evaluate_object_typed(acpi_dev->handle, "_STR", + NULL, &buffer, + ACPI_TYPE_BUFFER); + if (ACPI_FAILURE(status)) + return -EIO; + + str_obj =3D buffer.pointer; =20 /* * The _STR object contains a Unicode identifier for a device. * We need to convert to utf-8 so it can be displayed. */ result =3D 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); =20 buf[result++] =3D '\n'; =20 + 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 =3D {ACPI_ALLOCATE_BUFFER, NULL}; - acpi_status status; int result =3D 0; =20 /* @@ -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 =3D acpi_evaluate_object_typed(dev->handle, "_STR", - NULL, &buffer, - ACPI_TYPE_BUFFER); - if (ACPI_FAILURE(status)) - buffer.pointer =3D NULL; - dev->pnp.str_obj =3D buffer.pointer; result =3D 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 1a4dfd7a1c4a..2f202ac5f1ef 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -254,7 +254,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 */ }; =20 #define acpi_device_bid(d) ((d)->pnp.bus_id) --=20 2.45.2 From nobody Wed Dec 17 13:56:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8007F15216C; Tue, 9 Jul 2024 20:38:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; cv=none; b=jNjePHC0Db3PH00N3UyA6aY5BSKQNVefXhGgY9shSzVWvcbcXoLRxSUMPHTHSyXrNhOwGCbX/1MIg5cOSO4mxHS5Ap9UcZW62oXUvwElLOEEJcdUPTxMQaYY1KDGJRvJpd4JSXRkyh0H4GNBcU3Q8bsu5A1LgsdgDAm80i04ELQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; c=relaxed/simple; bh=wyLNNonp+7EAIRxVIHE6cr9kx2sg/BjXOWQjvwkKSCM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O3E2VXyL2P1zDJ6kM75Iz9rI4hPO8Uk1yrQ/SkyyjFBvIODfwv6AYz4kTHdtZFN/S2n/cgSIUZqkzBtxMtp+DT5u4oNY1tm6ImI0WUDzXkHE0Aaqh3DVFYl/IJ6akQApoj9sTO2oVLjIZxzmqEUtSTxIFmXYR5yh8U91T2gubsM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=iMpczcb/; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="iMpczcb/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1720557499; bh=wyLNNonp+7EAIRxVIHE6cr9kx2sg/BjXOWQjvwkKSCM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iMpczcb/9M3jdlnikdvV5lUhKrdmEjceGz9oSduRI0vGQFccMLfCENkfPiDuFI1Z4 HoQHMT2xpUHs/RYWkP3T19NKrwlxBqoMLmCyK8nlPCNu/56EplV5bN/AHG22RSuneq OAciqts4ElioDTGq3Hhpa/ZPuV9Ne/YOUbix74kI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 09 Jul 2024 22:37:26 +0200 Subject: [PATCH v2 3/5] ACPI: sysfs: manage attributes as attribute_group Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240709-acpi-sysfs-groups-v2-3-058ab0667fa8@weissschuh.net> References: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> In-Reply-To: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown , Robert Moore , Lance Ortiz Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720557498; l=6564; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=wyLNNonp+7EAIRxVIHE6cr9kx2sg/BjXOWQjvwkKSCM=; b=FRzNK3aA6OUYBjF/kHmDwML61eKtIbMW2Ak1zSYSPnRsnbazRKNaQ+fwFMw9p08hmbOi7BV4e 9GkfrVmIUn6ChJ/2mvbB2wurFRUbePl6/foP/kNyoURyQF2YpbPJhKw X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The current manual attribute management is inconsistent and brittle. Not all return values of device_create_file() are checked and the cleanup logic needs to be kept up to date manually. Moving all attributes into an attribute_group and using the is_visible() callback allows the management of all attributes as a single unit. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/acpi/device_sysfs.c | 167 +++++++++++++++++++---------------------= ---- 1 file changed, 71 insertions(+), 96 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 6e4858ea035f..4afc773383ad 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -517,88 +517,97 @@ static ssize_t status_show(struct device *dev, struct= device_attribute *attr, } static DEVICE_ATTR_RO(status); =20 -/** - * acpi_device_setup_files - Create sysfs attributes of an ACPI device. - * @dev: ACPI device object. - */ -int acpi_device_setup_files(struct acpi_device *dev) -{ - int result =3D 0; +static struct attribute *acpi_attrs[] =3D { + &dev_attr_path.attr, + &dev_attr_hid.attr, + &dev_attr_modalias.attr, + &dev_attr_description.attr, + &dev_attr_adr.attr, + &dev_attr_uid.attr, + &dev_attr_sun.attr, + &dev_attr_hrv.attr, + &dev_attr_status.attr, + &dev_attr_eject.attr, + &dev_attr_power_state.attr, + &dev_attr_real_power_state.attr, + NULL +}; =20 +static bool acpi_show_attr(struct acpi_device *dev, const struct device_at= tribute *attr) +{ /* * Devices gotten from FADT don't have a "path" attribute */ - if (dev->handle) { - result =3D device_create_file(&dev->dev, &dev_attr_path); - if (result) - goto end; - } + if (attr =3D=3D &dev_attr_path) + return dev->handle; =20 - if (!list_empty(&dev->pnp.ids)) { - result =3D device_create_file(&dev->dev, &dev_attr_hid); - if (result) - goto end; + if (attr =3D=3D &dev_attr_hid || attr =3D=3D &dev_attr_modalias) + return !list_empty(&dev->pnp.ids); =20 - result =3D device_create_file(&dev->dev, &dev_attr_modalias); - if (result) - goto end; - } + if (attr =3D=3D &dev_attr_description) + return acpi_has_method(dev->handle, "_STR"); =20 - /* - * If device has _STR, 'description' file is created - */ - if (acpi_has_method(dev->handle, "_STR")) { - result =3D device_create_file(&dev->dev, &dev_attr_description); - if (result) - goto end; - } + if (attr =3D=3D &dev_attr_adr) + return dev->pnp.type.bus_address; =20 - if (dev->pnp.type.bus_address) - result =3D device_create_file(&dev->dev, &dev_attr_adr); - if (acpi_device_uid(dev)) - result =3D device_create_file(&dev->dev, &dev_attr_uid); + if (attr =3D=3D &dev_attr_uid) + return acpi_device_uid(dev); =20 - if (acpi_has_method(dev->handle, "_SUN")) { - result =3D device_create_file(&dev->dev, &dev_attr_sun); - if (result) - goto end; - } + if (attr =3D=3D &dev_attr_sun) + return acpi_has_method(dev->handle, "_SUN"); =20 - if (acpi_has_method(dev->handle, "_HRV")) { - result =3D device_create_file(&dev->dev, &dev_attr_hrv); - if (result) - goto end; - } + if (attr =3D=3D &dev_attr_hrv) + return acpi_has_method(dev->handle, "_HRV"); =20 - if (acpi_has_method(dev->handle, "_STA")) { - result =3D device_create_file(&dev->dev, &dev_attr_status); - if (result) - goto end; - } + if (attr =3D=3D &dev_attr_status) + return acpi_has_method(dev->handle, "_STA"); =20 /* * If device has _EJ0, 'eject' file is created that is used to trigger * hot-removal function from userland. */ - if (acpi_has_method(dev->handle, "_EJ0")) { - result =3D device_create_file(&dev->dev, &dev_attr_eject); - if (result) - return result; - } + if (attr =3D=3D &dev_attr_eject) + return acpi_has_method(dev->handle, "_EJ0"); =20 - if (dev->flags.power_manageable) { - result =3D device_create_file(&dev->dev, &dev_attr_power_state); - if (result) - return result; + if (attr =3D=3D &dev_attr_power_state) + return dev->flags.power_manageable; =20 - if (dev->power.flags.power_resources) - result =3D device_create_file(&dev->dev, - &dev_attr_real_power_state); - } + if (attr =3D=3D &dev_attr_real_power_state) + return dev->flags.power_manageable && dev->power.flags.power_resources; + + dev_warn_once(&dev->dev, "Unexpected attribute: %s\n", attr->attr.name); + return false; +} + +static umode_t acpi_attr_is_visible(struct kobject *kobj, + struct attribute *attr, + int attrno) +{ + struct acpi_device *dev =3D to_acpi_device(kobj_to_dev(kobj)); + + if (acpi_show_attr(dev, container_of(attr, struct device_attribute, attr)= )) + return attr->mode; + else + return 0; +} + +static const struct attribute_group acpi_group =3D { + .attrs =3D acpi_attrs, + .is_visible =3D acpi_attr_is_visible, +}; + +/** + * acpi_device_setup_files - Create sysfs attributes of an ACPI device. + * @dev: ACPI device object. + */ +int acpi_device_setup_files(struct acpi_device *dev) +{ + int result =3D 0; + + result =3D device_add_group(&dev->dev, &acpi_group); =20 acpi_expose_nondev_subnodes(&dev->dev.kobj, &dev->data); =20 -end: return result; } =20 @@ -609,39 +618,5 @@ int acpi_device_setup_files(struct acpi_device *dev) void acpi_device_remove_files(struct acpi_device *dev) { acpi_hide_nondev_subnodes(&dev->data); - - if (dev->flags.power_manageable) { - device_remove_file(&dev->dev, &dev_attr_power_state); - if (dev->power.flags.power_resources) - device_remove_file(&dev->dev, - &dev_attr_real_power_state); - } - - /* - * If device has _STR, remove 'description' file - */ - if (acpi_has_method(dev->handle, "_STR")) - device_remove_file(&dev->dev, &dev_attr_description); - /* - * If device has _EJ0, remove 'eject' file. - */ - if (acpi_has_method(dev->handle, "_EJ0")) - device_remove_file(&dev->dev, &dev_attr_eject); - - if (acpi_has_method(dev->handle, "_SUN")) - device_remove_file(&dev->dev, &dev_attr_sun); - - if (acpi_has_method(dev->handle, "_HRV")) - device_remove_file(&dev->dev, &dev_attr_hrv); - - if (acpi_device_uid(dev)) - device_remove_file(&dev->dev, &dev_attr_uid); - if (dev->pnp.type.bus_address) - device_remove_file(&dev->dev, &dev_attr_adr); - device_remove_file(&dev->dev, &dev_attr_modalias); - device_remove_file(&dev->dev, &dev_attr_hid); - if (acpi_has_method(dev->handle, "_STA")) - device_remove_file(&dev->dev, &dev_attr_status); - if (dev->handle) - device_remove_file(&dev->dev, &dev_attr_path); + device_remove_group(&dev->dev, &acpi_group); } --=20 2.45.2 From nobody Wed Dec 17 13:56:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1096417B04F; Tue, 9 Jul 2024 20:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; cv=none; b=tjl3R1dQSoH0y8dy1YPa3FsrLplSnVaKRJ2geybY0wZTRvg+2UshvFgtX0Sjvifi0YKSj8lZz6gNNryGlDwC1wS29e3X49TUElHv99ywCzEFcjRYbjUDL9cWWM1VufJqiAbrKJ0G3XmX/yTsSi789P/HA4OaYcWSygG2l9IxRV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557504; c=relaxed/simple; bh=UKdBAWRdJurn3EAUsp76SpgIaDEnD12ErHFCnETITyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dBJFkqa1+hkkxrWt8k77uYtOo+r+SSetC45VhNUB6oKWNpkp1fklVo2LTsxPbvirgZbaLZ+j9ABzBRT+sEOFzwJrfLKOdznd3PVbcBXcKRh15Mlq/bDEKrqi82oKF9Xac5+GrAEy+7bRYHBcsW6svls8B4h2c26A95pUXGcuRA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=C6iWCBvL; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="C6iWCBvL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1720557499; bh=UKdBAWRdJurn3EAUsp76SpgIaDEnD12ErHFCnETITyU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=C6iWCBvL2B9UpP94EfRbGsY/0hoUDM/ojOGBTvFA0Q75auCVq2LinWgtaF9kfAXyB oPXFplKKaiou9o2vMp7TJyM1FtrtAM/v0CT0Fdx/aBhGypdQheIw9n/QAXX/XBuwt7 lnG7TA5LhkebGzV1uE9u+YYSjrsmJsHzluGSdnqQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 09 Jul 2024 22:37:27 +0200 Subject: [PATCH v2 4/5] ACPI: sysfs: manage sysfs attributes through device core Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240709-acpi-sysfs-groups-v2-4-058ab0667fa8@weissschuh.net> References: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> In-Reply-To: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown , Robert Moore , Lance Ortiz Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720557498; l=2513; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=UKdBAWRdJurn3EAUsp76SpgIaDEnD12ErHFCnETITyU=; b=AAIJkN+pFjK5krlVuFD+yFRS+7724cbJsJFZ0i3GH52IA12jh/g1JVtPAcLPqV5r2BNbLZlTq UZDGdUBeH5HDA1AM2BMr9ZQRwcY4FZscVYMO7RUrrhewKZuvwQ7vygd X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Now that the acpi sysfs attributes are organized around an attribute_group the device core can manage them. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/acpi/device_sysfs.c | 8 +++++--- drivers/acpi/internal.h | 1 + drivers/acpi/scan.c | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 4afc773383ad..0bff4a1654ed 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -596,6 +596,11 @@ static const struct attribute_group acpi_group =3D { .is_visible =3D acpi_attr_is_visible, }; =20 +const struct attribute_group *acpi_groups[] =3D { + &acpi_group, + NULL +}; + /** * acpi_device_setup_files - Create sysfs attributes of an ACPI device. * @dev: ACPI device object. @@ -604,8 +609,6 @@ int acpi_device_setup_files(struct acpi_device *dev) { int result =3D 0; =20 - result =3D device_add_group(&dev->dev, &acpi_group); - acpi_expose_nondev_subnodes(&dev->dev.kobj, &dev->data); =20 return result; @@ -618,5 +621,4 @@ int acpi_device_setup_files(struct acpi_device *dev) void acpi_device_remove_files(struct acpi_device *dev) { acpi_hide_nondev_subnodes(&dev->data); - device_remove_group(&dev->dev, &acpi_group); } diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 601b670356e5..8e1c21e45d0e 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -120,6 +120,7 @@ int acpi_tie_acpi_dev(struct acpi_device *adev); int acpi_device_add(struct acpi_device *device); int acpi_device_setup_files(struct acpi_device *dev); void acpi_device_remove_files(struct acpi_device *dev); +extern const struct attribute_group *acpi_groups[]; void acpi_device_add_finalize(struct acpi_device *device); void acpi_free_pnp_ids(struct acpi_device_pnp *pnp); bool acpi_device_is_enabled(const struct acpi_device *adev); diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 503773707e01..c15fffefca0a 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1813,6 +1813,7 @@ void acpi_init_device_object(struct acpi_device *devi= ce, acpi_handle handle, device->dev.parent =3D parent ? &parent->dev : NULL; device->dev.release =3D release; device->dev.bus =3D &acpi_bus_type; + device->dev.groups =3D acpi_groups; fwnode_init(&device->fwnode, &acpi_device_fwnode_ops); acpi_set_device_status(device, ACPI_STA_DEFAULT); acpi_device_get_busid(device); --=20 2.45.2 From nobody Wed Dec 17 13:56:02 2025 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C39918C16D; Tue, 9 Jul 2024 20:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557507; cv=none; b=GWEFAHMKrDDb/U4ko+HItF6Nt9Zl5iznu7Fgoe1on+ffWd7i6BMiqgpzZShM8FCqGVg+zw/CkYQhe31flFheyAhli6LEDrIQc0JoWMJzzHPO1K/TsMO0U5mU0+5lcUDTEVUhQM65LNHFUU9Q6N4GVMA2wyUIhWnTop1o77SPDEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720557507; c=relaxed/simple; bh=Sp5DrYzmn3EazYQ2PC86K+raUE9JkwKEQCb8FTClzrs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l+8YXT8+brpXlr+kD9CpA3yZDTmeoyo7n2NkQMQrckD1+CzysFEVR3zwFQ4S+JCRKoi6S65DO0hyu/SeJniW8AzhCqLUnj09uG/fhq4QcpoPmLs4snn658C9NzEpW/d7eKKdW9hNMVJ5DwFbOXaf0M78xDcXaejA5ZvoTs2lvZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=EA3+0yB2; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="EA3+0yB2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1720557500; bh=Sp5DrYzmn3EazYQ2PC86K+raUE9JkwKEQCb8FTClzrs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EA3+0yB2PHIBJKtW+y3CQIBw5APR8fXUtu2+dS0wz0E0csy5gCyo8wh+a+jMwogjp ZthHyPewjWYNfkTtvKxFGW0ZpG7cVfdTUAyAQFSWw1x5Bbr2uAKP2j2zxDCIT2s2Hv 7IRMtJ0bGjU9XZmK/+8ZJf/POcSUZlYRbwS1m4qs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 09 Jul 2024 22:37:28 +0200 Subject: [PATCH v2 5/5] ACPI: sysfs: remove return value of acpi_device_setup_files() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240709-acpi-sysfs-groups-v2-5-058ab0667fa8@weissschuh.net> References: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> In-Reply-To: <20240709-acpi-sysfs-groups-v2-0-058ab0667fa8@weissschuh.net> To: "Rafael J. Wysocki" , Len Brown , Robert Moore , Lance Ortiz Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, acpica-devel@lists.linux.dev, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1720557498; l=2071; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Sp5DrYzmn3EazYQ2PC86K+raUE9JkwKEQCb8FTClzrs=; b=7EuhOxj3EfzvjJ6IlNBC3jBTFhZv8oaD26FNHK1WVARBYCgFBEcOl4P9HVJcVh6FfMc8j+xOj ESnbwQWGUJ6AtnqHUsLtobZ0QUa3XboUCwZ5xRAsgYpcc0W0/JjI0qj X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The function can not fail anymore, so drop its return value. Signed-off-by: Thomas Wei=C3=9Fschuh --- drivers/acpi/device_sysfs.c | 6 +----- drivers/acpi/internal.h | 2 +- drivers/acpi/scan.c | 5 +---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 0bff4a1654ed..3961fc47152c 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -605,13 +605,9 @@ const struct attribute_group *acpi_groups[] =3D { * acpi_device_setup_files - Create sysfs attributes of an ACPI device. * @dev: ACPI device object. */ -int acpi_device_setup_files(struct acpi_device *dev) +void acpi_device_setup_files(struct acpi_device *dev) { - int result =3D 0; - acpi_expose_nondev_subnodes(&dev->dev.kobj, &dev->data); - - return result; } =20 /** diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 8e1c21e45d0e..ca712a7fde21 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -118,7 +118,7 @@ void acpi_init_device_object(struct acpi_device *device= , acpi_handle handle, int type, void (*release)(struct device *)); int acpi_tie_acpi_dev(struct acpi_device *adev); int acpi_device_add(struct acpi_device *device); -int acpi_device_setup_files(struct acpi_device *dev); +void acpi_device_setup_files(struct acpi_device *dev); void acpi_device_remove_files(struct acpi_device *dev); extern const struct attribute_group *acpi_groups[]; void acpi_device_add_finalize(struct acpi_device *device); diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index c15fffefca0a..49a8172fe0de 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -766,10 +766,7 @@ int acpi_device_add(struct acpi_device *device) goto err; } =20 - result =3D acpi_device_setup_files(device); - if (result) - pr_err("Error creating sysfs interface for device %s\n", - dev_name(&device->dev)); + acpi_device_setup_files(device); =20 return 0; =20 --=20 2.45.2