From nobody Sun Dec 14 08:06:23 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 ED446313266 for ; Wed, 29 Oct 2025 08:12: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=1761725544; cv=none; b=Cfi5x+j+D4dQhrbPVvlTPwZO14VSlp0Rlsiz4yIBiGqrmJ7r8yQB5jeDXJLdBi2TOSAZaGD1gJjAIwO7brGcV6r27RkYOoR0QkfNN7m752ymombtO8LHvyntNNKqhIKGaP36bp8SYe2RVzt4X5NAT+DRwu0l+NmFbNioF9cYsDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725544; c=relaxed/simple; bh=t3/9kWTcTSvqcCpxsztjc8iQ7bvxhMdLfhEtzrfuO+E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KAv4ilpwYuvKQGQj+3A98qKlaQQ8JB3c3t2+WiPJJiZ5cExhzrwjvNsiIBpT9JUtQQtpxeDSxrKx5/shUfEoAtBltYH01cIu9eKhyEvoAeM7OzQ8ALjUssu4PNs5TazuNu5E67+Ze0PKe1P3YzedmcdUUSrjmv/e/p7TIAKUjfU= 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=AHU5u7Ox; 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="AHU5u7Ox" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725540; bh=t3/9kWTcTSvqcCpxsztjc8iQ7bvxhMdLfhEtzrfuO+E=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AHU5u7Ox8OUF2xNjD8bXvzrUgHhWFZ2brLDkKruym8jqr3kWW9wye44HNTuYOm7Dl YowXhCehCIWs9mvaUrNAqbfVv6kqZZpmfbMecVVrVQJ98qom/rgYmy974wGTngBqN5 m0dr5Rg0zGh8l2MKPOCcjtG8TV1MSpTymEMYphyI= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:10 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-1-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=1501; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=t3/9kWTcTSvqcCpxsztjc8iQ7bvxhMdLfhEtzrfuO+E=; b=xk3e1UShGV2Gtg5Krq6Stll/0hLwqg3EwhuYea6hLStQ++HtTPNVLDZzcj7ZhDnW6rt0uplsp Z9r4hoNMkB/ClPijKvr26J1HZfs1dKqe0zf08uwFisOsO1rH1wRQMYi 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.1.dirty From nobody Sun Dec 14 08:06:23 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 ED3C62D46B1 for ; Wed, 29 Oct 2025 08:12: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=1761725545; cv=none; b=vCmbhj0OhaYItnUnnOpPLANbvm+ZIEDK3DbwEvRUtsPXs9irnv1+/DPX2CgDptACVaQy5pG+vuIZTNel8Es0Wr1LE4mp9kcqrdMbl5Y5rTF2L+A+/HqRHeUpv6GG5aNJ5wqsgt/GVILRreNZ0QZzPsZMDswZnh4pIo9ptwDfVY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725545; c=relaxed/simple; bh=4HQ+oUujCPeT8uI7nX/NsoBt7w0I2vvre4qc0JB8GYk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=knGCWOzVWKR31TAJjCwWGxpDuuZPUcdRFZcLVD1NO7iIj7nsFJrxEo/jpVEfyxLF2lszpzv7fLjK6CObW9npbxtwjWxVX9EFbeKiJ6feVA7NNDHIoTF32AwAEnoTaQmqtK4+bieiL7yubUEk/0Iminb5z1AgAIqBgZSoAUTNeUc= 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=gNUrkF03; 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="gNUrkF03" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725540; bh=4HQ+oUujCPeT8uI7nX/NsoBt7w0I2vvre4qc0JB8GYk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gNUrkF03iHqp9nzsuJ9prig5meibKL898LlFCH3Xnm8gE0A5ySXEC+3/MUjhFbsVL y1ze0EPWbYfyLcgqKur5MaAjKNjTHgXDFmFXqTrstS6OQhJUWGalMGk3DX6ShAQpMq D1HzoIXk008EyRTo7KNGCIn94ejh1GYLH1Sj0L4o= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:11 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-2-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=1050; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=4HQ+oUujCPeT8uI7nX/NsoBt7w0I2vvre4qc0JB8GYk=; b=eSQrKMY1d0c+XRWXYiVrT1bZkLGuX2Snxb8zFwWvkHqlkpNRAB3tsO+GumJOhXlFxEsn1pOWV OL3nKv7VPR7CdPpWnvdT1r7tK44MkRp4DN5ooNAjvqF1yAbcsKlDza9 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.1.dirty From nobody Sun Dec 14 08:06:23 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 B4179313269 for ; Wed, 29 Oct 2025 08:12:23 +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=1761725545; cv=none; b=gB/5gPxbj/pO7NUOKloNjMhx5TXdfMCFGLox5i+iscWdbricV0VRL74Ds0gIt7CH6Tr+W0oosoDFBQ2UxClKNI6/yXMM+Ta/jehh0osg4DHABF7opFci44ajKnZ0NvaiFvECVIaBH0M94Q/8ZgZbZwpDRTtDlpZIEbjLYssWWnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725545; c=relaxed/simple; bh=T4GDySY+12QZFTxg7oIvleS0IgVlOECCc0h2coxbMA0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J5u2mBbh6JnoXDIWwJf200YyvAYde8fFUhoBdkPQDiRlWeodx1ZyEw2TmUd+amme2Z0SMS/Wf+sS4wksg+et4xyYOj4iHaCX2WhQMEwzgaGt11Qz1JzOBJ/H8f4ztsPZBXWFgARQUyfFyTFuDL2QEb0HEHkzrAKlrkDtEOtamhM= 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=Thh1dyLx; 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="Thh1dyLx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725540; bh=T4GDySY+12QZFTxg7oIvleS0IgVlOECCc0h2coxbMA0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Thh1dyLxtdLmGPqCarFWbEBPHOQW3lzvi68VQjds6zmvqDpKxpR2/D7ZYGvP9a9TE Ej5dYwRVY77E/LMVk1MC8jCB7NCD0MPbUhpGGPO0TIxVFwH/JP89yXRme7px+dejkZ TBfEusXpUcZgl1ouZIhZoehu5nuRWsYtnaYPwwt4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:12 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-3-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=1343; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=T4GDySY+12QZFTxg7oIvleS0IgVlOECCc0h2coxbMA0=; b=gkobSXD0pzF5SBRjlRFzcx0oGQBnLPHHOKoz6DOR5+LkDpB81dUhtlXzfUv+IeqOo4bJcI0IM gQRQHoP8amZCkMcuOiOYj3wZ+M5Wtejfbx6s6Nx1PGLZlGCRRTa7WBg 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..9cef5bf24ba7 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 +#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.1.dirty From nobody Sun Dec 14 08:06:23 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 44C6D1D2F42 for ; Wed, 29 Oct 2025 08:12:23 +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=1761725544; cv=none; b=lGGw2DVXNtCCC0MPmr1n+C/R7TchPUcK3LeU76K1puiWwQPcPCMo7EGKegxCdjLZtkbsg+qRzih8GjZQ6WOenHxYjOEG3jo6wPPbKGPijVRVoRjGJJliaE2GfhdBUJJNo+zT/Y2Npe7Jrxlmyzo47nYMfYSsQMl7gaaJ2sB1VH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725544; c=relaxed/simple; bh=N004Uk3t+Ean9/Bx8sNBms7jh3PkbCRlHcUdP2D8ljo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uqcPqsTMujlStGra18u93dbch8wb0y5UeklWvliPzj/gM5/wK/lEHWNHe2oV8JG+ZxKJHxjo55tBLJiEeEsT/fCZ2nTTL/asenlytqya1F42MDPDDPhRaUBTAn3MB8OncfW7HLWXAt4CphqammdzFv/cXZn1JPzb3PolInlgdqk= 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=oeE4A9wc; 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="oeE4A9wc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725541; bh=N004Uk3t+Ean9/Bx8sNBms7jh3PkbCRlHcUdP2D8ljo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=oeE4A9wc2smFbM0ORoITpFk/lAn6f5RTubgi1W52n3vc7skVJIkwGZGsWN+UVcKfm 41ARKfPVOZrYImN81zDj+/JkpsLPqRoz3+YKnQkhQbJ433qMd+14sacbKljhQIkV82 uLvVbMPWHyM+RDjWotkjyMMiyP09R/b5gtmxIrIE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:13 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-4-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=2230; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=N004Uk3t+Ean9/Bx8sNBms7jh3PkbCRlHcUdP2D8ljo=; b=3suqCqDRglkoPZYAa4LmBL+2dAQXGm0fcTtq2krt5jb1GkSjTxVRmqN4uNVqTTqt5WDn3Dh/p Hj0Z1eAsxuCBA9PV2awHP11VPW1oHgOvB39iq974hvrxzARGkdtolnJ 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 9cef5bf24ba7..592886ed6ca9 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.1.dirty From nobody Sun Dec 14 08:06:23 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 613D431B11C for ; Wed, 29 Oct 2025 08:12: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=1761725548; cv=none; b=lV3oSNyet6J1Sotj+qyVr+35mwJj1ih8ljzP2/8Y02Nq9rplmnva11KlyxgQAKHSwEUOjSt8DIgfpjqQVTmFOPrxXV0JrwiehfW7eBO57wDnw9mnQXVdYhDFYpJ3f3RZc4MdPSAcOY7uCZKElO9BKUwMxxirfKpY7Iyi+j9dZHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725548; c=relaxed/simple; bh=C2IydpU5hcWQZVOVyKtsRIF55iGkuvWV7aaqsvWnHQM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aDn5QyLSk/RFCoPa6fAOvy2QeR4cUIbU/SLzbU/4umVV+pzlRW4Bu597BcQZOSMIeJ+WR2qeBI7WK4/62zhAZRSeELbAcxBbVTf3lzNLDvAxSWRB4aAcQ8gejMUaYint3YPjmvntHmLrOWA8RpXNHEezxlqhvm8f/z1JMaVelFw= 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=U/lEPiZn; 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="U/lEPiZn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725541; bh=C2IydpU5hcWQZVOVyKtsRIF55iGkuvWV7aaqsvWnHQM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=U/lEPiZnoYuN9VNzuatzhfazDX8nEgb0324K43YOftXidUWw5NUdwL47D/bzjFBR0 jFnliB6WX646DyqsQ3RCCn5ZC87JVA4uyrk1dBrK46R/nFsRkrrFurmwaN4jlFAND9 EKA2nZPe/sm6RseX3KEPwhSDGhwYQv3qGSQAQtuc= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:14 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-5-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=1281; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=C2IydpU5hcWQZVOVyKtsRIF55iGkuvWV7aaqsvWnHQM=; b=5JML33F84eRJeO6ECh7AtZ/qswSN5jCvGmupGuhkotk9V3EtY7OMqUYk1iUh36x1eF1QzBf14 2l2pOaHaQOUBiuBul3h4JMimbzpjEJqG+KxWAaUdpsZT2NqwX2Q7vjH 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.1.dirty From nobody Sun Dec 14 08:06:23 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 795AE31B13D for ; Wed, 29 Oct 2025 08:12: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=1761725548; cv=none; b=GkWDFPU7Zj8Ur6oMiMJe+mc+FNCySg/4NDubGNTqWg1HlHZGbQInKiPg46xUpqFA2j/kok0z6lptsq7UgYxXNFehTrQV/ydNhfjU4gicBQII+d26MOC3fihLogFydLfZXv7NVcrS7bCFj8Q1IdYQTarmC5iXtAFHq79Gw/Rm3Rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725548; c=relaxed/simple; bh=zwi8par5vtkFegTjW+L+jK9fi2Z7hkBmx/27Zh7tu5c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SF2JkqHpspOqrKo1T230O7BdGnJD0tTgzZoAa3vBjmPV+pok04dOWdyLQPug2dOuwbSMNJztPuEKtlCqkmpH78Zn7DkVtgYTEnLe0ffVH1eNGMF8td6BORUHtTsupAPRcz2sYFqcBFlOObzR1XKdGFacdHbCSXW9jazljeUVh3o= 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=GeqaIzU9; 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="GeqaIzU9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725541; bh=zwi8par5vtkFegTjW+L+jK9fi2Z7hkBmx/27Zh7tu5c=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GeqaIzU9xOMFGhliQiqqVvlqoZSXQAgYr+ZRIsYNKX91RvsR4bnjTnUePjWagRYBc vWwuqPq9KVfV5BEMASxpASJ0mzow3495dEWVgUsOSu5eY8CbwduUsfYauoIHzHx6Ps ajIk25LY0iuxANoA4l5q//8TOIRodLOwfeXGfohs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:15 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-6-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=4795; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=zwi8par5vtkFegTjW+L+jK9fi2Z7hkBmx/27Zh7tu5c=; b=z+AW9VAb4j7P0iH0EW+b+xZS66sMLvLWJJDzeMGF9mtb6SA5SepDdG4vxbaCRUvD2agkAuhO3 nQ03dhZzUJUBW8yq871S78cgn0HpN/2EfEse4X6qTuGRavST74g4GnY 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.1.dirty From nobody Sun Dec 14 08:06:23 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 73D8731B137 for ; Wed, 29 Oct 2025 08:12: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=1761725548; cv=none; b=Th/ZWgeGI982ohl7WmT1cXpMja0Y4pFbK/H3NSF/pmbtQT4MvunjOz5AcxqhkdAlZuPPxid/lLAKQk0OrgyeoEwPM25PkxjoYqSn1ORt/J/ldoyoV7GdfcM1nqLzBDslJ1C23OcjA2GGp8VQEF3u/wbPO7qbeIhyoIYpCPsCKIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761725548; c=relaxed/simple; bh=syHV3tyj6les3ZkK7XNdRxpEE5VUzXh5wQdxQ7YotzA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ryUFb4Yq4UtGqThEwf5JPmPNYxATrWH7BlM/p8VVk8TrauoooWyzQ+h5svrhA5TKRQ2+I7FUt9cPc7FrWAXP17Wlyd7slTND4BiW0X+02GOmnVbjPpSYGYw+4Lg5TLhj9VpFPeU5rRUDiqiLu5+7YuUkg486TgV7P8lLKWhNx+g= 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=Fq2271Uz; 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="Fq2271Uz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1761725542; bh=syHV3tyj6les3ZkK7XNdRxpEE5VUzXh5wQdxQ7YotzA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Fq2271Uz+9A2lAKYb4TIpYsXPH9Oeaz1WQEwlNVrDRb46GcgqSFW2Z8jBjyI+i4pt 5J5htRi5t/NVvLPp2zqLLQ0jpo1BoQs5f09tWT/8rceUIMJ6dAQs2nJR/kN8vgUsPY G1m0qPKNaN7jz7lAipSVjNEgEHprObW4WBWtAlmk= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Wed, 29 Oct 2025 09:12:16 +0100 Subject: [PATCH v5 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: <20251029-sysfs-const-attr-prep-v5-7-ea7d745acff4@weissschuh.net> References: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@weissschuh.net> In-Reply-To: <20251029-sysfs-const-attr-prep-v5-0-ea7d745acff4@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=1761725539; l=1943; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=syHV3tyj6les3ZkK7XNdRxpEE5VUzXh5wQdxQ7YotzA=; b=J/UyntzDaMe5tIDA7uFvK/eLolLaZq4DUB/HRcNI4P8VxeAKOnXw8inrSjVZYVUaRFol5ZRKz AES05Sg/xHBABZxrAOJiUtDyzf8XH/4eOFugybChzaCR4G0KUGqrzUT 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 592886ed6ca9..c33a96b7391a 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.1.dirty