From nobody Tue Oct 7 07:06:10 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 5D68323E324 for ; Sun, 13 Jul 2025 09:52: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=1752400343; cv=none; b=E3YkbUpKw9tct/YeuXfH2q/thmgCKmawlh6X3g3KYUPGV05MPEyn40ViWjtu6arnWoy3Hk4yIyAPo/p8ZuVdLL2QQZd0dfkrakkjzVHlEFzzsAptYkczFkCqcJkiXwIixR0nE1YdkUbT98SLGH075zQ331iN8WZ+85kuy19U3pI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400343; c=relaxed/simple; bh=GRXkHr87sMAwGXVCFiOsZuTbb8axjZTo4vNoebQJmjg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EkTlnLR6H9qfNWcHVqk1Br+Ig2rb1UibIdsbkAallDQYQCthy815D2jht6hGCQX2Ujf4aZtB2n9FdR1B955ozXlTStnHQFdZyRGbwaALs0JLZ3bFIxMMrbZr0BYjBOMSg6+n9z7yqCrsGu37ZyPKWht/TH0129WyYYUsul2ordM= 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=ZvMakQwP; 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="ZvMakQwP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=GRXkHr87sMAwGXVCFiOsZuTbb8axjZTo4vNoebQJmjg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZvMakQwPzbhylbboKeA8vCbB0AiKM6EesD8A0csE7diiUF/7a+KoB8F/JTTqbgNOn 5fcfO7QOdXU0rudXekX6WilPs3LNeDRLicjSUy3TcrkDHcqO7JzonVn83w8JaIVcvG HcK5MvKdVd+sy0VVbS/DuMOigDtiQCrrK5H9wCFU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:13 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-1-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=1606; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=GRXkHr87sMAwGXVCFiOsZuTbb8axjZTo4vNoebQJmjg=; b=1+s7+MHUMZ+qo33k3FuoOJ+UiM+DmswRzX8m8IE+4cWv0/Vx8dE4Dwp8bJZpd+uZSdNyhXnDs r5aZ52Ve9l3BmN5T3EMadyTJLex/VSsA+KbS5cHBwNJ6XVzMSNBMr3L 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 f418aae4f1134f8126783d9e8eb575ba4278e927..a47092e837d9eb014894d1f7e49= f0fd0f9a2e350 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_new; + }; union { const struct bin_attribute *const *bin_attrs; const struct bin_attribute *const *bin_attrs_new; --=20 2.50.1 From nobody Tue Oct 7 07:06:10 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 C7B091367 for ; Sun, 13 Jul 2025 09:52: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=1752400343; cv=none; b=g8UpiYNwSO6RuM3U+yFp2LUQXXqxY83jnLH2XukOKD5Jl31FMV7ZxdgYRydI90qiB4MPe8H6kGjOvDDjX+3VAjnEEOZ7oR0ZcEepFxdmUI9yWSFhnHWIVTtGwVCBaINOSEBkgrRKFzUeuoOHmE06pWyMTQbfD3ps/ttB81aEHAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400343; c=relaxed/simple; bh=kGwqGdBW3jjbIWNaJKunX6K1VPeiWAsjwBkGA4VS9Ms=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rt6cQhpgo2N+0n+CuUwjtnLsZaX8HWro+IA5szR1JZuWtaSwMZaRwtyEsR5lS7ytrOiLnfUVsVO5RIjFGPK+O2CeY+PigLlpeLjvD8cAgzCEAaQAveK8CYyvsEENfKFCvKpGP6qKyBnKmjLBFoyb1bn3hc7PFQHEvNcu5ZNdKfk= 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=L1o3wpR4; 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="L1o3wpR4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=kGwqGdBW3jjbIWNaJKunX6K1VPeiWAsjwBkGA4VS9Ms=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=L1o3wpR4/uaD1XuysbyqMYfRy0saVeMlYnF/9muRM7/jagiPBaGwi0z7iO6HsCqaT THgG0PFEu2ZTnh4G2f/mSRHgNAEYrRDIeSC8FQkRHiH9Ir0IP4gy0BjV6lOTd9ixPd XqZTW6lUX9WWPdYYwZgih9rxHskA5lWG7RfCs73E= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:14 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-2-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=1101; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=kGwqGdBW3jjbIWNaJKunX6K1VPeiWAsjwBkGA4VS9Ms=; b=4hPYEUEalkAwXTCOYkjuc2iWeoth6zBCsA6YbaujMbJGBu5rYbVWZtApHgfPni7VwlhE/F25p BzEuKCREBUMAH+sQeXoqfEzq24kj/n35UOWMp5QKkaNkR2Hyp4+2LM1 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 a47092e837d9eb014894d1f7e49f0fd0f9a2e350..118a9b1d3b3e7528fb213d83f85= d31bbac0dc309 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -290,7 +290,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.50.1 From nobody Tue Oct 7 07:06:10 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 5D6262309B5 for ; Sun, 13 Jul 2025 09:52: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=1752400344; cv=none; b=QM8FLoclDPUzjJu2ofiGfp9YoufKRU1M64nsjRS8wNgobMgz77icdq0GtJnPfGlX0oURgQD3ENFGjoZmz26btBBQsK7GRF123tjLW8JylOq0K57Dadzl+4EfE1HZiMxNBA2NevcZkO6HqDsvUNkDZUnRQIQ2CRq+FqYHsvLEcEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400344; c=relaxed/simple; bh=W87lX2sL3B1KxSSRP0r3YgrT1PIAqEhsSKd6TF5iAuY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WoouU2KdmTHNcSx8d02kLtas+6ig44zMOGdeIqOHNlDHWNi3eaacDg4Wf6hmB+/omRFox3NEZ+bwk6j+caqZF4Bc1mRZqyOhr2Gn/yE5LRuDpUP0psTEsYRp8wcKtC3IVyVIMgUvBQDXpeIvWbk7pY1U/GZxeSwBmHfjJmCXRog= 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=B3AJNb0c; 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="B3AJNb0c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=W87lX2sL3B1KxSSRP0r3YgrT1PIAqEhsSKd6TF5iAuY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B3AJNb0c0k1o0wJWQQiFjYJifBGO6RjNbojQQ8nyGO5TkEJxaFC52oH/yuoZfkEd8 wHLvlo7v4A79F5UFpROoC7iQ+LdgZ5mAYI7H8VV2jk/BsxW5EA1rY4KPSpe2l3FQVl zW+il3srtEuvSjkL8dr01K4/wWVChQ8yENXJGwvo= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:15 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-3-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=1400; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=W87lX2sL3B1KxSSRP0r3YgrT1PIAqEhsSKd6TF5iAuY=; b=uFmhsIH5cBfUOTqoCg7vj99HMgBB79/NP/9iUPi+cAryoypI+YoAL6eryyvJw3ZxsPh7KKF6r DoLdJi09gbuBPxNxnvxr5SNQmBFgJNjL1PSN3jm5AQ9OxytWo985DiU 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 118a9b1d3b3e7528fb213d83f85d31bbac0dc309..3966947e78b8c030971daf5ee66= bf5ab40bc2a17 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.50.1 From nobody Tue Oct 7 07:06:10 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 5D5BD229B12 for ; Sun, 13 Jul 2025 09:52: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=1752400345; cv=none; b=UYN6sAnvVRZduBlrXsjaPJET/2UUniUni+CkWJAQdNCFB3CW3v4CBAYA2swxpN/skK2738f78DjW2nfjg6a+ycfK5fbll1oHo9wPqq3FZPteV/P7tFf/Zj0HH6IMH2Gyoh+EbzxPQTUl8Xua1I/2Pejs7Pgo1x1D/TH0lQdSPyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400345; c=relaxed/simple; bh=cqU0PLp2RlumLkRgw/nfqdxzb8kyCbuP1/hjrIv1dXA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ueg6iS0/Ma2OS603qaw0QATvCJ37mfHu2ybgq5QYLFLs98UQZE6+gRl1E4ni/rVMA9isMBaO086NB5wNiICUa1NGzQnDQjWnr0+hnqNo8A9oAxlBZ5VhRpkpSlYJgQHumfo2/zJhXg6cR0F/310pMdu1a5omF0BRBEPEfFXVBbo= 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=aN/Q45iT; 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="aN/Q45iT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=cqU0PLp2RlumLkRgw/nfqdxzb8kyCbuP1/hjrIv1dXA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aN/Q45iTkSDD+sBLdo9zTCqiUvmyYJJoEE+bKqY8jt6vJirAB8nLZXP2AJlvm+w0C OGp21/zFHxWYqcunEZq16keDXVclpdrBL5PJ5860ZyoCLs/waW6Rdlz+H218MhY2JI r9d3wmoQiwAt8WLYsXBE6yxeG8ZBqZc9O38Gq7dY= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:16 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-4-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=2324; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cqU0PLp2RlumLkRgw/nfqdxzb8kyCbuP1/hjrIv1dXA=; b=c2eiy6d/OAyhonhtJqg1+m6pw56aE6poIKvdj1niMHOn1cbpm1KdddyTu5Ae0Na+RTCttsr8u Lvo6lZOuK+bCjpK5FJy+0kCCJz1SRRhJUJNciU1r7g/JM2/Krjnyczk 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 2d78e94072a0d4ed957560c60cc3c5dd49ab6fb4..d514ce8ac4d964676006dc45a31= bb9f5fe5fd5dd 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_new) + return grp->is_visible_new(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_new) { + if (grp->is_visible) + mode =3D grp->is_visible(kobj, *attr, i); + else + mode =3D grp->is_visible_new(kobj, *attr, i); mode &=3D ~SYSFS_GROUP_INVISIBLE; if (!mode) continue; diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 3966947e78b8c030971daf5ee66bf5ab40bc2a17..1807b0369bd4d993deab81c4497= 903468b751a19 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_new)(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.50.1 From nobody Tue Oct 7 07:06:10 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 91F9E277CA9 for ; Sun, 13 Jul 2025 09:52:25 +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=1752400347; cv=none; b=FPOMQT3lJ0bOuuH8UgeLxI2X5bh6D78iVwGy/+GHVjW4T2PRvo/XRSBTSEkb/tlVuMMqBQV4CnzFzXko7OKvRiD474RfHpxWDg0ieHvv3wde9D+dZ2RwwEkuVCiQK+Ui+dLwbyu96ftjDy6bhJqW34MqXCcB4K/1hxjMs97RL70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400347; c=relaxed/simple; bh=Z//Faceuwef39wP/7RdyrYvgfLi9/56AANS8dtYn4Ug=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eTvM40ABnDKlJ/Ds0DBIIEWpVHXwGaV/sftub0bp6S/i9Kssgv4rx2zKpvBwpj8Lx3ChyXTkc4MadH6TBas5uH2m9hRkRfFqkL8xo/fjqpbCmNa7wRH0TaO+71GbXXK4tXRkdan2iGFxoeXjCQEpWQm5lUktqbgdvazXkY1TdD0= 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=IVoEelo/; 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="IVoEelo/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=Z//Faceuwef39wP/7RdyrYvgfLi9/56AANS8dtYn4Ug=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IVoEelo/prYQzxczKUMzM6n3aRFRCfChR5hzZHl1Of59In4InKz6YEnMD6D3Kild3 EMMxTmt+Gy1cgJZmqNxEitiGXJvMXTtDaBQ0V2v7OYZo6P1b2D61S61Q69AR5arDYK i8dOVfFb73SrUNWO9gRF8D6Kzx/3xHgbC9j89jBg= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:17 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-5-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=1331; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=Z//Faceuwef39wP/7RdyrYvgfLi9/56AANS8dtYn4Ug=; b=PJsEbGuzxyboB1sZTgIsX5Xk/jm+ebciTYh94GnU/XLuDXLhwRv+cd8G3i0gAUqHdxEEgGFr5 us9gJk5CXIIBG1A991keKD2u5bCgP4z3vmOcEjASwM5CZjNHGys2c2o 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 552d7e363539a8f82ab8e0446c732f85ed2c5612..7d8c68763ff8af696cbafaed1d5= f1b173bb4860e 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.50.1 From nobody Tue Oct 7 07:06:10 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 3BA45277C88 for ; Sun, 13 Jul 2025 09:52:25 +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=1752400347; cv=none; b=qozeBvKXzN3A6n1z5BI7nTUPxnACoIRGzR/Tw/QLzr8iE0bzSCLE5Pu6AT1akRQBls1RVqNmdBgHay/+4U8jDQ0i6bxTuiDynwjJEGUkN/NKn8Jp6irDtbCPbuq6rmXLhJYHFtM8sfthrAG52DgCEke9JaKnTi//hCGu4tzXdZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400347; c=relaxed/simple; bh=3jbICsVpA2/tf5f0WVhMM1PQ4J75Rl/Lh/mqHkdc5+8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XMufCDKrQYXHsywM6/tXobEX/JudSN78Jr8WKSiRcKIuFpGQGrGdYF4XWYuaB5ehlWzf9rG8UlfQzfN1e+MHT6EO5eJp3fLELlzo9+xSUjN2XWfZbe0LVD8HQWkOJp2+30vdlEyupJb0uOsO1zSI5WzEOdPEICXJrRFnxTwQ0sA= 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=MoOMLLNP; 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="MoOMLLNP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=3jbICsVpA2/tf5f0WVhMM1PQ4J75Rl/Lh/mqHkdc5+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MoOMLLNP5+RH13BwADejGnwVLUifNeTfK54NPEvPkmTyPX5Bo7x8Z2NFVXKFK1jqW d/+CDUMg7/Jp/NKlb23xvOeiwr6rSIit2yXsUPX77hbYOxcrTIV+mjLxg8mL3mpWhp ZZBkSCnsBQ81ciIw6hyuifHnyzuUjRED8E+WpUXE= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:18 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-6-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=4840; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=3jbICsVpA2/tf5f0WVhMM1PQ4J75Rl/Lh/mqHkdc5+8=; b=5lR+dSVgSfO9u++R6+i1FkWThVVt6k2ougLCPMN5V+bmkGwwRU5wHZfpqNrhJs5isOLGSUuHQ 75NZoIw74pcDJZNcvUISxzv0NMscri17mJpR3XBcCd5ertMwTOF0jyt 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 7d8c68763ff8af696cbafaed1d5f1b173bb4860e..cbcfa628cc2801a7c4fc0d86889= 8c4cfa539825c 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_new =3D foo_default_attrs, + .is_visible_new =3D foo_default_attrs_is_visible, }; __ATTRIBUTE_GROUPS(foo_default); =20 --=20 2.50.1 From nobody Tue Oct 7 07:06:10 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 18C7427780D for ; Sun, 13 Jul 2025 09:52:24 +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=1752400346; cv=none; b=b6brgpqJZPR2QoykewxA/XIh+YJ5xqnx6fvPab7D7wg4Ugic/2UcrjCPwhuIoKsvkaNGEmDmfXELiE27a0gaffLf3QWQhxkTbixOy13Kq6FvsB2U7Thynl8HMhggp/2xLuT50VhvNCxl4l/LyVNLqPhma+AfCeZnW7QA+r2qECs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752400346; c=relaxed/simple; bh=cdJ7D3EdF5PJUi2CpxhbFNXtNwJFZM1ws1Y5su+CL44=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B4KURm/tcSbGPQPgnVgixQnnFWPk8Rg3Iaqjsfr4nNDRGu0nl+UJL763TPWz0CYk135J/Yu+JX0BjK7vDyb4BhPaGW0glfiyrtT3aAOD6Fv+K2gyaZxt3NznuD1EJWOw1hVVsyoh4b9TKJjLMfIk8U9Us+Gc/l43rX6Cgj2F4qs= 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=rHuXrBe/; 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="rHuXrBe/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1752400334; bh=cdJ7D3EdF5PJUi2CpxhbFNXtNwJFZM1ws1Y5su+CL44=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rHuXrBe/2R8baWoV8a7QViSmRkmX8IQZlMtR/tCxBhzVUZieTB02UgidgZ4eurHDX AYtkfu1obeV+zKcL+3AaWSsIO0auWrKUsHbskpJmXyRnU5IpJEFExIBlBpl/E+JNw3 UChKfpKq4jB2hyxUE4gSzM83IceVFclhHwzzggvU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 13 Jul 2025 11:52:19 +0200 Subject: [PATCH RESEND v2 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: <20250713-sysfs-const-attr-prep-v2-7-2f42510318a5@weissschuh.net> References: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@weissschuh.net> In-Reply-To: <20250713-sysfs-const-attr-prep-v2-0-2f42510318a5@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1752400333; l=2010; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cdJ7D3EdF5PJUi2CpxhbFNXtNwJFZM1ws1Y5su+CL44=; b=BWuOOJHvLGvd04yz9wDHBC3eJ5miHxOPhZCnWKKN06p6MfAZYKQuzio1wWoKTLMkTEC5Nqv4M brcIcBeT58oA9Sh+Q+A1JXVo3IvCsvn11pIhPTei5+FRK+qtFvSXNsF 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 it does not occur inside the current tree. 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 1807b0369bd4d993deab81c4497903468b751a19..2d6f984e10a96ab9916024ae7b7= 2458edf0c5bd6 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -254,28 +254,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.50.1