From nobody Fri Dec 19 15:36:04 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 548F130AD06 for ; Mon, 13 Oct 2025 15:18:00 +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=1760368681; cv=none; b=IjkG3b3W0ux/50iPYTqi73s45+8Currz0dvHVUc2n9VQyzihZP195+ApSRYGgGub++LUIPGQe7vnL5gq8ZdeFce8pBJqveAm+NyU92GI75u+GiEmxMO2P6YMxqTcljUbib0fA5cAlR7SHSBL8sEb7MBGv4WZJZ35EBhChPrXxWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368681; c=relaxed/simple; bh=e2JSNt1oXoBuC8lD+VFhcIHgvuTQyriVtTtr7YhY1Vc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R4niVaTpGtNmlZ2vEVPFJ3xwTeD1Fe/yHubCGGaXFPepcuMUTnK46stbIJj2b6i4SSHVwRsby8/3tmzMO7nl6bkLjs7g5jmRytvStkM3eN1NCv/7oUvVlDhjftDXCRfYsbIRlqS2Jk8rQGN0zyPobOrAe5NFB2j2gH5YYMRqmak= 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=o9ZLZVWe; 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="o9ZLZVWe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368677; bh=e2JSNt1oXoBuC8lD+VFhcIHgvuTQyriVtTtr7YhY1Vc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=o9ZLZVWexMfJhNKk55vlXeiB66nToOeYajBMQlJ6aB73IkdaTOQov8gLm+kJ8q4/5 6km4m4iKNU7V0+KK454i77ttK6iMjOyQrRBRFqMfT3HWU22j7gZ0AdzXpa5CkkrahS 4fUG6vN2w/KBMExQLhpE/lnY9q3KfV9L4aFNVWZA= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:17:54 +0200 Subject: [PATCH v4 1/7] sysfs: attribute_group: allow registration of const attribute 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: <20251013-sysfs-const-attr-prep-v4-1-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=1495; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=e2JSNt1oXoBuC8lD+VFhcIHgvuTQyriVtTtr7YhY1Vc=; b=VSkGZc21lexL4OfqHzIiLkqrvhA6zPcck9sfBEX5qLK/U6SZYmwqiT+JDhETQLtKzUqaRLtRm mwAO5VYsJY5AaEifBLkCRqMB945SGTeezd1iOtwlm5fpbMpV+IYgI4I X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= To be able to constify instances of struct attribute it has to be possible to add them to struct attribute_group. The current type of the attrs member however is not compatible with that. Introduce a union that allows registration of both const and non-const attributes to enable a piecewise transition. As both union member types are compatible no logic needs to be adapted. Technically it is now possible register a const struct attribute and receive it as mutable pointer in the callbacks. This is a soundness issue. But this same soundness issue already exists today in sysfs_create_file(). Also the struct definition and callback implementation are always closely linked and are meant to be moved to const in lockstep. Similar to commit 906c508afdca ("sysfs: attribute_group: allow registration of const bin_attribute") Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/sysfs.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 9a25a2911652..e34d6af96abb 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -105,7 +105,10 @@ struct attribute_group { size_t (*bin_size)(struct kobject *, const struct bin_attribute *, int); - struct attribute **attrs; + union { + struct attribute **attrs; + const struct attribute *const *attrs_const; + }; const struct bin_attribute *const *bin_attrs; }; =20 --=20 2.51.0 From nobody Fri Dec 19 15:36:04 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 A6CEE30AD03 for ; Mon, 13 Oct 2025 15:17:59 +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=1760368681; cv=none; b=TQErcx3AYYUCr+jqEuXZgBB4yqWpQKXB2RB/m0EtsRFgVTiyJTAzB8r52XXLBtJexDhQ1hYtu496NMR+daeAVr7izNF1PWZ8cBMJVumj3DQVQ7u1WiaMVIvOFBzfqsv0WAAsyYpyZANx1+/QtQq5+BXIDHNCj4vB/IHnCSA/hCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368681; c=relaxed/simple; bh=HC4YPP7F9f5/8XpQpN3pCxcZl4ZWvihPACOD9G2RUOs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OFVmP/LtDhMqXAny1MZ8k99yfa+ZZXRI59lgN+jjoRPZ3jDZdTTMmr/73hbNz0C1PNLjyOQSZwhVkTdDgo7jvJX9iQkPZWys8qhEeL+KBGk4f3KGoj3f5dGVA/YrsULxJEnPx75pEWjed8QPEN3zmPYRaQ2tb1o49BeVJlPJ7nc= 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=XgzZweWk; 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="XgzZweWk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368677; bh=HC4YPP7F9f5/8XpQpN3pCxcZl4ZWvihPACOD9G2RUOs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XgzZweWkP7HgPeOFK9l4odAyT04nglkkumkMx27cnoVs2pkVXggCIwfpDV0xBk80S GsArnGU2HgnAzLBMeUiO1XQB5ZFlxDOQjnaBohoJHmn7OjNWA52L2eRVfxjB5U5yyz oWVYBOm7gDHzWCyZ2VRkr5uqBT0YKgfit+xG6n0I= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:17:55 +0200 Subject: [PATCH v4 2/7] sysfs: transparently handle const pointers in ATTRIBUTE_GROUPS() 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: <20251013-sysfs-const-attr-prep-v4-2-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=1044; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=HC4YPP7F9f5/8XpQpN3pCxcZl4ZWvihPACOD9G2RUOs=; b=8Dm8CIpShyi3yU/5hFkgvK0gYk3znKEYFfCh/zw22A3BzEpvZXPacg/YduEZSssDfOh9tZOuc HK+Ttsp/xEEBuL039wdPDwolgm0cFqO8+ZREtu6ArtM0CZYpAMaUZ7D X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= To ease the constification process of 'struct attribute', transparently handle the const pointers in ATTRIBUTE_GROUPS(). A cast is used instead of assigning to .attrs_new as it keeps the macro smaller. As both members are aliased to each other the result is identical. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/sysfs.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index e34d6af96abb..92f82cee5f11 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -287,7 +287,12 @@ static const struct attribute_group *_name##_groups[] = =3D { \ =20 #define ATTRIBUTE_GROUPS(_name) \ static const struct attribute_group _name##_group =3D { \ - .attrs =3D _name##_attrs, \ + .attrs =3D _Generic(_name##_attrs, \ + struct attribute **: \ + _name##_attrs, \ + const struct attribute *const *: \ + (void *)_name##_attrs \ + ), \ }; \ __ATTRIBUTE_GROUPS(_name) =20 --=20 2.51.0 From nobody Fri Dec 19 15:36:04 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 D8BD330AD09 for ; Mon, 13 Oct 2025 15:18:02 +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=1760368684; cv=none; b=Of4RZweaF74XMPrMp+VV64c8kTeiS7efxfMGpDcjPpHUU69J6P4+9/YdP792aWhcAR4JSycgAl3FozGDLgqs3Jj4fk1MkkRy9LJA4+XU6QjBsil5nRBAy+m3xm7aQDFoLele3G60GFiSmMOR98JR3b44K3/6vEAfJblRMFB4FGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368684; c=relaxed/simple; bh=hzol1noZC1ZW5OidI1eG4X/7ERixSktCfo7WToDn4Ic=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=he6jEV8+top5Lyl4yqATdMmhOmjulTzxiz+WZWByJ6HgYwU6AtGNkFwF6k3wI+vKHWiug/jFXHqeA/U1X8PqWb0+oJpb470T/qDcZCIojGfuKc0gYf8LB82w6efwWmzJTvLzwC0r3HIGi71JHMuUJVQos52mQeGPlndv1H9kgBo= 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=YX4mAnnB; 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="YX4mAnnB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368677; bh=hzol1noZC1ZW5OidI1eG4X/7ERixSktCfo7WToDn4Ic=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YX4mAnnBzUwomHzXUgIMl2M+CAK0tIw9IopNhPdO2q63jnDfhprMgs79xFo9+63ca OLCE66+d70A+kgN4y4OWkPJNe7aCpVd2kx/iNEXqYF/7gWiSe8OgMueDdn9LQVydYf +/h+J2ekBUhS5nr4TOLX2uVM2HVuQB8/8mMo2Hfw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:17:56 +0200 Subject: [PATCH v4 3/7] sysfs: introduce __SYSFS_FUNCTION_ALTERNATIVE() 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: <20251013-sysfs-const-attr-prep-v4-3-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=1343; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=hzol1noZC1ZW5OidI1eG4X/7ERixSktCfo7WToDn4Ic=; b=DxQQe91LKiMRQGS7dyyMuogPmI/jmlZ9J0F4SL+pwO8xdJv5/sGpd2pqAPkIyHEC4wBxqgTSJ SPb4KYXzDTYBVqZHt0tUxjqtvhVfbprr8CHmgnh2MHuSbK2b3uCWz7W X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= For the constification phase of 'struct attribute' various callback struct members will need to exist in both const and non-const variants. Keeping both members in a union avoids memory and CPU overhead but will be detected and trapped by Control Flow Integrity (CFI). By deciding between a struct and a union depending whether CFI is enabled, most configurations can avoid this overhead. Code using these callbacks will still need to be updated to handle both members explicitly. In the union case the compiler will recognize that testing for one union member is enough and optimize away the code for the other one. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/sysfs.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 92f82cee5f11..02e5a9f946ee 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -58,6 +58,12 @@ do { \ #define sysfs_attr_init(attr) do {} while (0) #endif =20 +#ifdef CONFIG_CFI_CLANG +#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) struct { MEMBERS } +#else +#define __SYSFS_FUNCTION_ALTERNATIVE(MEMBERS...) union { MEMBERS } +#endif + /** * struct attribute_group - data structure used to declare an attribute gr= oup. * @name: Optional: Attribute group name --=20 2.51.0 From nobody Fri Dec 19 15:36:04 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 D68CD30B536 for ; Mon, 13 Oct 2025 15:18:02 +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=1760368685; cv=none; b=dcGpmuYCGLBzB+UeA0uyf9g56LWzmVP5K8iLlS0I0mB/qzmy3D+yNBrh8hbz9yaFOZVga7aFOFFfhK2q2+UczDYhnL4XqO1l4OjNrPdzYy81QZ/422jUxxDPYnefeyPtFKAKdjvvCHs/uYy0TgO0SIgbxM7yDNKLZTpVeA0l8E0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368685; c=relaxed/simple; bh=GOom/VXkrSCRhov7K+YLJwNjxxlLOnx4LbzK593FkGQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kX7uhLfpKbk56MXKTvNE+u94myi4nT+v9+HhofSlmTrrc9nUrgWQceYUSApMxkaLAlineb+aT5PUqBxP1jdQ5PLFjUDkeGwUsPVLt7+wi5ATwl1G4/ljHzcDylG60Zt+VD395FHFBpTwCtCkrqcFnmqAg/bOF9bB4JcLuWzIhSQ= 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=uJosDbx9; 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="uJosDbx9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368677; bh=GOom/VXkrSCRhov7K+YLJwNjxxlLOnx4LbzK593FkGQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=uJosDbx9NLnMdwutCnrKYnOmwhXOaRi9T+8EAzc6vBGyyvme4v3033oayywOUDlhy PgV2+TIY142AClJBPicjrnboA5E0UsNqZl3GeS4NWwOl/gTzKcJDCZFxZcTsbFqoHw oLJY+fi90H/ZCft6pKHe21UB1S8vKqAOwjiF+LwY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:17:57 +0200 Subject: [PATCH v4 4/7] sysfs: attribute_group: enable const variants of is_visible() 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: <20251013-sysfs-const-attr-prep-v4-4-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=2224; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=GOom/VXkrSCRhov7K+YLJwNjxxlLOnx4LbzK593FkGQ=; b=th7heMjy6iwHyODvgr4g8uZaZfnH90IGd8oyw0Kaaq73erpiM9BYspJa9VHGPNeweuPBom5RN eP9zbchFCNsB6icC6fBAWraKcrWlIM9bUT465sJjVD8HXiP5YqOKeRi X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= When constifying instances of struct attribute, for consistency the corresponding .is_visible() callback should be adapted, too. Introduce a temporary transition mechanism until all callbacks are converted. Signed-off-by: Thomas Wei=C3=9Fschuh --- fs/sysfs/group.c | 10 ++++++++-- include/linux/sysfs.h | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 2d78e94072a0..d53570953617 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -36,6 +36,9 @@ static umode_t __first_visible(const struct attribute_gro= up *grp, struct kobject if (grp->attrs && grp->attrs[0] && grp->is_visible) return grp->is_visible(kobj, grp->attrs[0], 0); =20 + if (grp->attrs && grp->attrs[0] && grp->is_visible_const) + return grp->is_visible_const(kobj, grp->attrs[0], 0); + if (grp->bin_attrs && grp->bin_attrs[0] && grp->is_bin_visible) return grp->is_bin_visible(kobj, grp->bin_attrs[0], 0); =20 @@ -61,8 +64,11 @@ static int create_files(struct kernfs_node *parent, stru= ct kobject *kobj, */ if (update) kernfs_remove_by_name(parent, (*attr)->name); - if (grp->is_visible) { - mode =3D grp->is_visible(kobj, *attr, i); + if (grp->is_visible || grp->is_visible_const) { + if (grp->is_visible) + mode =3D grp->is_visible(kobj, *attr, i); + else + mode =3D grp->is_visible_const(kobj, *attr, i); mode &=3D ~SYSFS_GROUP_INVISIBLE; if (!mode) continue; diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 02e5a9f946ee..ec4aed8c8181 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -104,8 +104,12 @@ do { \ */ struct attribute_group { const char *name; - umode_t (*is_visible)(struct kobject *, - struct attribute *, int); + __SYSFS_FUNCTION_ALTERNATIVE( + umode_t (*is_visible)(struct kobject *, + struct attribute *, int); + umode_t (*is_visible_const)(struct kobject *, + const struct attribute *, int); + ); umode_t (*is_bin_visible)(struct kobject *, const struct bin_attribute *, int); size_t (*bin_size)(struct kobject *, --=20 2.51.0 From nobody Fri Dec 19 15:36:04 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 0B21D30AD07 for ; Mon, 13 Oct 2025 15:17:59 +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=1760368681; cv=none; b=AtmRzlZZwx4Vt9M6rvsPQb9fulvjrC917lODbvGcafjG9eyXH45RjsXHNDWDRrDZhv1Ih59akoRW6vWUxmABicAPKr+7oBQpesm2XfJ0JEZfwtgpwBnlq6CnLkJFVhwotG5cHHfcTEvm7XwT72DGYp9fAtBCf0epc3URZWvk+KU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368681; c=relaxed/simple; bh=dm4gTICqg1OgZaecjOSXE0OQrJAwU67NZfNKwaH4c3g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qQxik+JZ49JUz/tZRqVNzpuFhe+FiPLSOx3kghF1/3A4JA46vzEjUqfJ1Ii9BoJ2Y9hkMZ2/Ma8sllGEHBJ1qDbJI6jHV9j8Nd8WFDR6Wm9BHzp7YBnqDgtHyW3X3FcF3546eLgPnysgTJ1ZWyraDI1FFmnGijiDazs5Gac2M5E= 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=gvpolZHj; 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="gvpolZHj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368678; bh=dm4gTICqg1OgZaecjOSXE0OQrJAwU67NZfNKwaH4c3g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gvpolZHjecBcORbnp+/DhkBvjDScZsZ44gsoeiOUGQF9QliiUW5jan5zxs4UPPano ccyeUadTgsjjlWDzh5mvO6g6Tzo1sNBsuTSj/X7speDlHaXnO0KbB3gSQr25Olw78s 5hlo/LxhMbPxKW5naNGIkJm8ZUeMO0Bb978kkg6M= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:17:58 +0200 Subject: [PATCH v4 5/7] samples/kobject: add is_visible() callback to 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: <20251013-sysfs-const-attr-prep-v4-5-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=1275; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=dm4gTICqg1OgZaecjOSXE0OQrJAwU67NZfNKwaH4c3g=; b=B8MMKxepjwjk2NJ+wbUDB9FnqXY/K50XUPXNHtULvEtcic+Gz2bLDObnlKyL2lXYV9e94Avwg xakxUN5/jG8CQKrXvLeNg0P3MABtLtczY1bu0qEs/IXu/8oHu7vxH43 X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= There was no example for the is_visible() callback so far. It will also become an example and test for the constification of 'struct attribute' later. Signed-off-by: Thomas Wei=C3=9Fschuh --- samples/kobject/kset-example.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c index 579ce150217c..1aac595ed949 100644 --- a/samples/kobject/kset-example.c +++ b/samples/kobject/kset-example.c @@ -178,7 +178,22 @@ static struct attribute *foo_default_attrs[] =3D { &bar_attribute.attr, NULL, /* need to NULL terminate the list of attributes */ }; -ATTRIBUTE_GROUPS(foo_default); + +static umode_t foo_default_attrs_is_visible(struct kobject *kobj, + struct attribute *attr, + int n) +{ + /* Hide attributes with the same name as the kobject. */ + if (strcmp(kobject_name(kobj), attr->name) =3D=3D 0) + return 0; + return attr->mode; +} + +static const struct attribute_group foo_default_group =3D { + .attrs =3D foo_default_attrs, + .is_visible =3D foo_default_attrs_is_visible, +}; +__ATTRIBUTE_GROUPS(foo_default); =20 /* * Our own ktype for our kobjects. Here we specify our sysfs ops, the --=20 2.51.0 From nobody Fri Dec 19 15:36:04 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 4AEAE26F2B6 for ; Mon, 13 Oct 2025 15:17:59 +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=1760368682; cv=none; b=q80kDHYo8x9D73IicUrAdRIgUhhyDLeooYQof9YXPkWoEksLsuRqAY9GgaJ2R5UYit59e4o32ezYvD1BxhQ/tidzB8+VNcE7WxjWneXvXQ39Fmc6ndjXLHaq5OTYpHNwpQczIlhiVft9KFkzxI8eicBe/X1c8AcIxNiSHiIo1Nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368682; c=relaxed/simple; bh=jtH4nqrbURxDtbqUUGMOoaGUnTfAq2JKQKzLXrOzIpY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=i12KyJWULFyqDBhe0X1BKAeAgnPmj1chJFnYiL/Egi5krAX/EM4Q5hMooIvtgOhhlOEjC7nDKLcPZmAv+xssYF/yH9Bj3FxRnG68a1dMdnJZmFCbm/lHPXPK2nvkhiirGKeDXZn80+/fewMEfTpLqtBjteZqf+ucSp6OdE82V+o= 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=i2rBRGxb; 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="i2rBRGxb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368678; bh=jtH4nqrbURxDtbqUUGMOoaGUnTfAq2JKQKzLXrOzIpY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=i2rBRGxbhNl50nLtal4Um8IT09REPlqsMLxr4gUA1P21E6CwF+MnduiESdb8iopJA yoLpipuRUIkkv3kscQ/06Rnc7dIg7hnlTA7EX3e6LQ6BBdH6TeGfAiKtV+km7SCFgx mEic+1KPDJDBA9FYMySEanyDKdRNlWkC51dld8pY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:17:59 +0200 Subject: [PATCH v4 6/7] samples/kobject: constify 'struct foo_attribute' 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: <20251013-sysfs-const-attr-prep-v4-6-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=4789; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=jtH4nqrbURxDtbqUUGMOoaGUnTfAq2JKQKzLXrOzIpY=; b=lp0D02DLitbshf3HyhZmHvI9JmGPs59xMqHmCiLFuEKwn+CqrzrdFC86pVwL9pHqmqxXuxoyg UUtbakz4856BY/r64YVZBKSk3ZNEzDd2f55m0ZdQ/hGEUj3tSTNkL8g X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Showcase and test the new 'struct attribute' constification facilities. Signed-off-by: Thomas Wei=C3=9Fschuh --- samples/kobject/kset-example.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c index 1aac595ed949..d0103904e5dd 100644 --- a/samples/kobject/kset-example.c +++ b/samples/kobject/kset-example.c @@ -37,10 +37,11 @@ struct foo_obj { /* a custom attribute that works just for a struct foo_obj. */ struct foo_attribute { struct attribute attr; - ssize_t (*show)(struct foo_obj *foo, struct foo_attribute *attr, char *bu= f); - ssize_t (*store)(struct foo_obj *foo, struct foo_attribute *attr, const c= har *buf, size_t count); + ssize_t (*show)(struct foo_obj *foo, const struct foo_attribute *attr, ch= ar *buf); + ssize_t (*store)(struct foo_obj *foo, const struct foo_attribute *attr, + const char *buf, size_t count); }; -#define to_foo_attr(x) container_of(x, struct foo_attribute, attr) +#define to_foo_attr(x) container_of_const(x, struct foo_attribute, attr) =20 /* * The default show function that must be passed to sysfs. This will be @@ -53,7 +54,7 @@ static ssize_t foo_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { - struct foo_attribute *attribute; + const struct foo_attribute *attribute; struct foo_obj *foo; =20 attribute =3D to_foo_attr(attr); @@ -73,7 +74,7 @@ static ssize_t foo_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t len) { - struct foo_attribute *attribute; + const struct foo_attribute *attribute; struct foo_obj *foo; =20 attribute =3D to_foo_attr(attr); @@ -109,13 +110,13 @@ static void foo_release(struct kobject *kobj) /* * The "foo" file where the .foo variable is read from and written to. */ -static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *att= r, +static ssize_t foo_show(struct foo_obj *foo_obj, const struct foo_attribut= e *attr, char *buf) { return sysfs_emit(buf, "%d\n", foo_obj->foo); } =20 -static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *at= tr, +static ssize_t foo_store(struct foo_obj *foo_obj, const struct foo_attribu= te *attr, const char *buf, size_t count) { int ret; @@ -128,14 +129,14 @@ static ssize_t foo_store(struct foo_obj *foo_obj, str= uct foo_attribute *attr, } =20 /* Sysfs attributes cannot be world-writable. */ -static struct foo_attribute foo_attribute =3D +static const struct foo_attribute foo_attribute =3D __ATTR(foo, 0664, foo_show, foo_store); =20 /* * More complex function where we determine which variable is being access= ed by * looking at the attribute for the "baz" and "bar" files. */ -static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr, +static ssize_t b_show(struct foo_obj *foo_obj, const struct foo_attribute = *attr, char *buf) { int var; @@ -147,7 +148,7 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct f= oo_attribute *attr, return sysfs_emit(buf, "%d\n", var); } =20 -static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr, +static ssize_t b_store(struct foo_obj *foo_obj, const struct foo_attribute= *attr, const char *buf, size_t count) { int var, ret; @@ -163,16 +164,16 @@ static ssize_t b_store(struct foo_obj *foo_obj, struc= t foo_attribute *attr, return count; } =20 -static struct foo_attribute baz_attribute =3D +static const struct foo_attribute baz_attribute =3D __ATTR(baz, 0664, b_show, b_store); -static struct foo_attribute bar_attribute =3D +static const struct foo_attribute bar_attribute =3D __ATTR(bar, 0664, b_show, b_store); =20 /* * Create a group of attributes so that we can create and destroy them all * at once. */ -static struct attribute *foo_default_attrs[] =3D { +static const struct attribute *const foo_default_attrs[] =3D { &foo_attribute.attr, &baz_attribute.attr, &bar_attribute.attr, @@ -180,7 +181,7 @@ static struct attribute *foo_default_attrs[] =3D { }; =20 static umode_t foo_default_attrs_is_visible(struct kobject *kobj, - struct attribute *attr, + const struct attribute *attr, int n) { /* Hide attributes with the same name as the kobject. */ @@ -190,8 +191,8 @@ static umode_t foo_default_attrs_is_visible(struct kobj= ect *kobj, } =20 static const struct attribute_group foo_default_group =3D { - .attrs =3D foo_default_attrs, - .is_visible =3D foo_default_attrs_is_visible, + .attrs_const =3D foo_default_attrs, + .is_visible_const =3D foo_default_attrs_is_visible, }; __ATTRIBUTE_GROUPS(foo_default); =20 --=20 2.51.0 From nobody Fri Dec 19 15:36:04 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 40CA63128B6 for ; Mon, 13 Oct 2025 15:18:03 +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=1760368684; cv=none; b=BSj70aZtfxjmtRAxA1I1STivCTbVlo2eIT8iMidVd1Iy8+Lgwp1OULZE+TTuzGy+UliU7ct089pSOEl0no1JkHtLpUVEfl4FKwgRNQEGDJMI0/sVKy1bz+KSX/fPyxX5dcP9vS3UT0DKKTA0jTBcykKZpZoyF3tCInwy2bf/rX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760368684; c=relaxed/simple; bh=EMXTzVHacQ1r9rYJzvj8RPO+T9sQPK+/cpWqLdb5FT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fP24JsTi3ge2RaCvH8LdUZWduJ9lAHrbUaprdEMNlDksfFo/zi9rX7A/+Wdq4suya/kOsLDUHynSSrWcgngAAU1Kz05XE+e1U1PWc54RrbAxjFscLuUdEm8N/pA+qaVY+TJSw7DH6ZulnE7y26jeK8cqbr48/AyvZjuj9NGdT7E= 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=GxaKm0VB; 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="GxaKm0VB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1760368678; bh=EMXTzVHacQ1r9rYJzvj8RPO+T9sQPK+/cpWqLdb5FT0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GxaKm0VB+cc/c9X5j2pVJpDa3bkXMAopOKyicEcKqUDSEeY0pKEOI9jWOUlpKgqhu RBiRiD1k6XM9Ap9ijBYH53X633s+hqzjY76oStC+RFdkJG2bwW4ZIdOZkUUsFF8exZ pFW+/Oh1L9aUeScOQKEgxCZRAv2cETRl33t3T81k= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 13 Oct 2025 17:18:00 +0200 Subject: [PATCH v4 7/7] sysfs: simplify attribute definition macros 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: <20251013-sysfs-const-attr-prep-v4-7-e0d36e828334@weissschuh.net> References: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> In-Reply-To: <20251013-sysfs-const-attr-prep-v4-0-e0d36e828334@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1760368676; l=1937; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=EMXTzVHacQ1r9rYJzvj8RPO+T9sQPK+/cpWqLdb5FT0=; b=n9YHRjuatErfi4EG0WyI/TEBJh5u/9bNGdnjdgWr4qY7t4Y4JKvE+0eHCfVeT6+Y0kVD4sYac OJ9sjT3D2PnCzHhXZFF1rpEeMXBYQKeNr326JSHadnCX0pwKVxd8ZAD X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Define the macros in terms of each other. This makes them easier to understand and also will make it easier to implement the transition machinery for 'const struct attribute'. __ATTR_RO_MODE() can't be implemented in terms of __ATTR() as not all attributes have a .store callback. The same issue theoretically exists for __ATTR_WO(), but practically that does not occur today. Reorder __ATTR_RO() below __ATTR_RO_MODE() to keep the order of the macro definition consistent with respect to each other. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/sysfs.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index ec4aed8c8181..5ce303dec7d7 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -251,28 +251,20 @@ struct attribute_group { .store =3D _store, \ } =20 -#define __ATTR_RO(_name) { \ - .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ - .show =3D _name##_show, \ -} - #define __ATTR_RO_MODE(_name, _mode) { \ .attr =3D { .name =3D __stringify(_name), \ .mode =3D VERIFY_OCTAL_PERMISSIONS(_mode) }, \ .show =3D _name##_show, \ } =20 -#define __ATTR_RW_MODE(_name, _mode) { \ - .attr =3D { .name =3D __stringify(_name), \ - .mode =3D VERIFY_OCTAL_PERMISSIONS(_mode) }, \ - .show =3D _name##_show, \ - .store =3D _name##_store, \ -} +#define __ATTR_RO(_name) \ + __ATTR_RO_MODE(_name, 0444) =20 -#define __ATTR_WO(_name) { \ - .attr =3D { .name =3D __stringify(_name), .mode =3D 0200 }, \ - .store =3D _name##_store, \ -} +#define __ATTR_RW_MODE(_name, _mode) \ + __ATTR(_name, _mode, _name##_show, _name##_store) + +#define __ATTR_WO(_name) \ + __ATTR(_name, 0200, NULL, _name##_store) =20 #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) =20 --=20 2.51.0