From nobody Sun Oct 5 01:50: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 AFFE62DCC11 for ; Mon, 11 Aug 2025 09:14:32 +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=1754903675; cv=none; b=Y7fYuhagQ27IxJ0pOUXpgdWGVxggC7rRIsKTL57GQN9lE75K6WFsoGRx53oQb3u570WL5G6gRuit+3+d6NjnjEgOW3FR9YppAY1e3rudnqQuYs0xx+8+5iKldr8i/EbXn1p1O+lJnXavDU6CHIg44GBR6TR03kkzBLBXQPJCymk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903675; c=relaxed/simple; bh=GRXkHr87sMAwGXVCFiOsZuTbb8axjZTo4vNoebQJmjg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T3BBxlt8xSqPmcTKQnF6ziqCARTn8uTAEvFQse2uRVHmpulnla4o0usOxZR+tvU4K1wKChuM633gr6bPyRw/178iXonN9N3ouzF/73Jfc63iupZTiIG7PhZ0HpHCq/Ja2MSzFC4pxHmKhHl4qjL/25FslUY5YA/o0sx+f8lfSgo= 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=hbShq/hb; 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="hbShq/hb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903670; bh=GRXkHr87sMAwGXVCFiOsZuTbb8axjZTo4vNoebQJmjg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hbShq/hbT9SaJ5IoYzGUUjJARmQwRNfVufjfd4G9aTvY0KzetVyToRaPBJZ5W80JP Xa/+A/81fV0QM6MJ518gJTYswB2GZ0osPB3LkIv7tkttW44+K6MKdSHk5WFuVM3E9t Ee+FhgVASdu4FKecqV9uE9R3D4PabotVlHCKYzKU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:27 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-1-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=1606; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=GRXkHr87sMAwGXVCFiOsZuTbb8axjZTo4vNoebQJmjg=; b=BqLrH4TbeVI5edSMiKvXCLPRUbwZKdFjlY6fb/Jbql32J2K8aVx/Ng49CQjQUcvbrpFP/jF/e J/ySe+J+i7xCZ88RGo5YYRMR8pgB68cyleTMgnK84V0H+GvjVF1IRTu 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 Sun Oct 5 01:50: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 BFCD12DCF5A for ; Mon, 11 Aug 2025 09:14:32 +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=1754903674; cv=none; b=A5tzq96s0TFbi24wesIDjSRsVJ710IFuNDoAfbpyd1HJ6wavQZ15wKbaXWLiirGe4snh717K3oDCv8AG9rWtvfpyrdLTbpIGGteHBuF3HUyBGH+LIOC7H+H5ftkbbBdh1KjxQ0jF7aVtmou39320aJTJVarQA61+k3CWUZgFFXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903674; c=relaxed/simple; bh=kGwqGdBW3jjbIWNaJKunX6K1VPeiWAsjwBkGA4VS9Ms=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ObJVv2DPHj8nF81XDrqaHNdg2v9mCOYSgRvFw2aODRJrAxt0KXBlZh6qV+2YhWTc8wtL/ucs5CQp46LgYpB6Ds65n4h/okVgExNZBTCUnYF2g/vQ3qennCCHh5Mkw++y0TJsQqmrbqUZ5TijTeTLLnyCCVAdcqsxxCrmG0pg+N8= 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=BWllO9h/; 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="BWllO9h/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903670; bh=kGwqGdBW3jjbIWNaJKunX6K1VPeiWAsjwBkGA4VS9Ms=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BWllO9h/1iVmKCAyPpFe/dzFSgCMIiyQU1KDs1LVI/Z8RbXbu6oQa5XwLDy7P5T93 6wh0WwmCgEsgGhUNgXM/drhKqIzWI1IZ3MDJfleFWNztWwljodhooLVMXgKt3HLEwM HfIOSEy5MSE+xu40HVmUvgWqsThqv+AYkYlKzoD4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:28 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-2-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=1101; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=kGwqGdBW3jjbIWNaJKunX6K1VPeiWAsjwBkGA4VS9Ms=; b=YoFO/BTW8Ds2teuPPG2QBfkTDZV0GcQmt5U44DxRDTqvcHbngmh3NID0wSDVDD9Jvl8xHaWjU gJ8PbVwKKNYDy4OXXUqckImzeS2yFOg2Ub+7KuX3ED7gWSDHgCBYIHI 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 Sun Oct 5 01:50: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 B006C2DCC1B for ; Mon, 11 Aug 2025 09:14:32 +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=1754903674; cv=none; b=qTzAfB5gJU6sSe0WfUDRQNtDrQMTdkR6pgUsI3+XLdhYmrkRwO78xI2MLXoQ4htBybzqizpJmFgB2h9x6yzshXh96Uf1YSeu+B8Zimhw/bzmXTc9VsdjCrIJ8Xow//Vn2IxVSTvsrP/mQsLC87SqzRONfZoV+8hj/jJLaqCPuX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903674; c=relaxed/simple; bh=W87lX2sL3B1KxSSRP0r3YgrT1PIAqEhsSKd6TF5iAuY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hRmPb4vICvw2j7pNuehLHI+yD68ab+37VtOMT/nSX3IHjnWnZrPqlWi/t8SzaXRCyCZ+85ys5xSYQhUGrSzsREVPjPmPQt1LwtxMzvD7rRSPx+2sAMbOvBkVAMIFOJKhdZWWHvNIx8lFVlflLdJfd3odQDSZ7gX0iON8VOJkNoo= 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=Di/Vm8G4; 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="Di/Vm8G4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903670; bh=W87lX2sL3B1KxSSRP0r3YgrT1PIAqEhsSKd6TF5iAuY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Di/Vm8G4S8ogRplpGNWFyEQPAj9PUoYv8tDA/GslcuuiOPq8tJ2IXCCJI1/ZPDCfH k/cvKVEvimXyn5xgWNzHTmB5JKic8/UfM//29yhutQgIJ7U0+WszveSYpQsAJgCFLp 1C0+qRgS6soE5rWFxqXeEDn4SiDBBNu8DMotTn9Q= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:29 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-3-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=1400; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=W87lX2sL3B1KxSSRP0r3YgrT1PIAqEhsSKd6TF5iAuY=; b=zj5BTNH0VDhanoakw49qtnXU1O4RnvHWsQGfmJzqI/Rq1mvldEuz36vnc6j5ouAHh2tKb5tDo aVX+bVGMaXvBVGNygSldchvyi3wIWB6nF+LuXv8vFH+q7teOPhAjms9 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 Sun Oct 5 01:50: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 364F82DCF6D for ; Mon, 11 Aug 2025 09:14:33 +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=1754903674; cv=none; b=AYf238T4WEGeooK4MYBUxrRQsHuM1WQD6uvDUn6pVnjwrPHAEUSbUzURsjfmsXD5ONS6c48R4GG6DnEsvrwgL2QglRx8TxVV533GboDZnmRSrPGW8g0zDyJcy9m11y7W68WBXxF8YGm6EC9kWvoUX06tSe+2ZZx+5YhIc8jiAUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903674; c=relaxed/simple; bh=cqU0PLp2RlumLkRgw/nfqdxzb8kyCbuP1/hjrIv1dXA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TnR5F6xA7Q+43TVZ7tSeKV/rIvlhRI3+CpsVQGviqKyHiVR+tnxMHXFtsWow1SqsjEpj4QowkdVRYmdQnrVM8pZMpa4HbpwIFTSBFT8pRb87NyVGWOD1hfKiQyffHVTrntEHNq86C5NwIoHicoipThV6Q0PuoeSw3CtsHq4apkg= 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=p86CrrAF; 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="p86CrrAF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903670; bh=cqU0PLp2RlumLkRgw/nfqdxzb8kyCbuP1/hjrIv1dXA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=p86CrrAFy3lri5B9JhUbrGbmxR74avy5v4CSfHWllyxthz5f8TJYgBewMxk4goTw+ PhwaNhjPhHHdvZpUX1Rzztan79vc3Ho62bklT3Xxy9YP8ZWu9E4W+2op0M4xvUSf5S Q0fIeq6Wih/JhXmAM+GIHG+hzoQWkNVlZXhGRX2E= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:30 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-4-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=2324; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cqU0PLp2RlumLkRgw/nfqdxzb8kyCbuP1/hjrIv1dXA=; b=z42UvULM4vkV5Mv93hSrMBmsfQEJf63fMxwLrKfplhy8oYVIDRMVgRf19jxtOs2Vk/4PBM7w9 yCOOuZDVv87ChQ9KhyQNyZAQjv6Us4qzy+k8cIujZC+x6K8V36AONKJ 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 Sun Oct 5 01:50: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 D3CA12DE6FE for ; Mon, 11 Aug 2025 09:14:35 +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=1754903678; cv=none; b=svSl5qPTKQSk42l2dkhbAwr+PLoZk/h+2RPECDFuRUyu+jke/tkhQZmWt4op5XUF0QUWkzdLup1RHXltnmv1NpaNHt0YPCypnA0U74p3UcN1WUuY0A19w+Y0Uh97YcvlAhskciYFlY3YUmFn2xPDzuIE1+LANFwzIqaY59oFXCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903678; c=relaxed/simple; bh=AIte5Rjg6BxBjZaqnkGlhXa3GSlWbi2KFz56gvpWyYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TtWR7a//QscGHEoMvc3BsSZy+I40oWcB9aHENPNywG6u7hzPFXFj5/0UGwvUibTk14q0WyBUCBRlIn/8ODRNe47PB5v9xFVOOkfCi44qCSn0VajufcszB1snhBxesHfz7EUsWOgA6nLpmE2Fte8afGCl9G70naGObub5j2G+fN8= 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=DvEvvSxA; 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="DvEvvSxA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903671; bh=AIte5Rjg6BxBjZaqnkGlhXa3GSlWbi2KFz56gvpWyYM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DvEvvSxA1+jVu9S6BVD+vKnDyv7itkUezwgNxl/4cBLi3gVu+vv5eRFIJrC+tFt+C DY9zqP++siDrT1yGmMrIw+GhT0jeijsplZjG/WAhjaa7xfRZ6bUvN+3dUgUDBSB3pQ 3UOzdwKVvJ2gZb2Ca6rNCqSs+daUGSdY1JpHYC4E= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:31 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-5-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=1331; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=AIte5Rjg6BxBjZaqnkGlhXa3GSlWbi2KFz56gvpWyYM=; b=Lb/bpjwn15cGqRhoBQwepr4+DWBfuULU/3jSb92Emnw3456ff85lTNO+hHadENsVQcoKQH45I ZpI9yC7XUg4Cpwi5fHw0TG5PAgX6j6R+nIJfxYpIq4RlYdWwLwsDGJO 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 579ce150217c6e613887e32a08206573543b3091..1aac595ed9498b30448485a60d9= 376cb5b5ea1d3 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 Sun Oct 5 01:50: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 D7D222DE700 for ; Mon, 11 Aug 2025 09:14:35 +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=1754903677; cv=none; b=oBU1MyVhD6Yxrwem/wf+WJ4d75ByWZHawxlkPdNHnveWgwbPQTwVoeysNv+rJ5U+q/mXtVEulpsx1/4J2MMWFcEy9lLSh2Gg6mktPyeHj87XDNdUYhZi+uQZO8AnqRntTAMg+TB48tc5z+5Pjc6wDoRdXJ1E1mOnWM9d2vYvjwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903677; c=relaxed/simple; bh=J3n7iY4dVHyBeeusKZymVzr82teU1K1OrA01DWdddpE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pXlsQ5F/UdpLtSpSmxFI9Efz/JsgRGMhCtL/h4ixY+u6mfQ/w3hLOYetguITLsgXifbi1KF+SEvQ74pPlIaqd3fhaWalAQuoBlN0ldgLS/LjGSJUOiHjdd/QrDo6QPTyVl2ZpLwyXYW+jS6mA0lejly4eTCexR6DjrigT6Rp3uk= 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=fv7QY5Ur; 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="fv7QY5Ur" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903671; bh=J3n7iY4dVHyBeeusKZymVzr82teU1K1OrA01DWdddpE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fv7QY5Ur/BXxSUWpGsdrHOXbcOsiNF8N5R2eeh/SLAXZhz14VK3rLxO/uJBZfslTe VyMw5ApF4c/hGet9VFNMJiXLETlt7pxYNUBvyuzTnI43CreQLFYixBD17qtXEzoXJd TemVGjvzmNelao8naCqZxSCTlDxB5vMSUSru9L2c= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:32 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-6-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=4840; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=J3n7iY4dVHyBeeusKZymVzr82teU1K1OrA01DWdddpE=; b=YN2A16RzLYct1zivce1+lS06YoR+lMnpRsW8849av036jQ6ci7t3fPhgyEkBycc1uv3prSLOT Q+vswRPggqAADq8VQZnFr7Vl1VuTj6yMngcC0rtpa0wQMxvGqtd2BGv 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 1aac595ed9498b30448485a60d9376cb5b5ea1d3..98aac6940f51f3312b44083a9d4= ffe7afed1dba7 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 Sun Oct 5 01:50: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 D794D2DE6FF for ; Mon, 11 Aug 2025 09:14:35 +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=1754903678; cv=none; b=RUxVLqXEQlmwuFNRBspD50LM43T/o2nS07AZubz8+xLBfI9Q5b9GBimZygpCV+XH7X9VbqJ4H1jdcoMxQsO1U7z7sqaHY6YKS3wPlGLz8UzK4w4Sj4blakPi83QconApc5ebGde6MhoQZfOpr2l25g+cf7xoxg7PzH2sqbsi7BM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754903678; c=relaxed/simple; bh=cdJ7D3EdF5PJUi2CpxhbFNXtNwJFZM1ws1Y5su+CL44=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KevtvgbKd5AuEBqLH7BbXEV86wTmCaDXXVtwGn02iBukWBzou/mEptD5RWxQiB+iRQWePALGVoshms3s9h6+aldL7MJHuqicuvwI5ZDymdgazot9YFiQoh4fQ+4CYI0pKzNc0yaBMSf3mggHat+ErvMHuA8b6Bx7tahX9Gqw8zo= 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=kj63iOfr; 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="kj63iOfr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1754903671; bh=cdJ7D3EdF5PJUi2CpxhbFNXtNwJFZM1ws1Y5su+CL44=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kj63iOfr2bPhwJYOKkj7Eh0v+DHYS7OVhhEU2/tkUctpyG4CQN0LrM6omCjnJXD+u 6/OeVAe8W+y9sBLvhLI5IgrZBIeq9o6Ym1M7iW1BcyQPVTMLhTzTUSB6Br/ZL8EjWy ZDHod72SqxMeZHxd9O2i6dC6Fppr7ySEfXx7DEXQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Mon, 11 Aug 2025 11:14:33 +0200 Subject: [PATCH v3 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: <20250811-sysfs-const-attr-prep-v3-7-0d973ff46afc@weissschuh.net> References: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@weissschuh.net> In-Reply-To: <20250811-sysfs-const-attr-prep-v3-0-0d973ff46afc@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=1754903670; l=2010; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=cdJ7D3EdF5PJUi2CpxhbFNXtNwJFZM1ws1Y5su+CL44=; b=kzVNGalD9eNFEMtg8sCQaMKLOI/ewpyE0vrzQMFYr5GEl+D3FumHTM8yS2fGKcZPVNmQITG37 t/iq4xQsb4FCcu68uuNL6NCbqhKEQVrX6G6fcDINyEcKMEUVLVL/CHz 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