From nobody Mon Jun 8 11:02:09 2026 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 A1D193EFFD5 for ; Fri, 29 May 2026 16:43: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=1780073010; cv=none; b=j7I6pgHiCCPJWyH3OJeGz09DzTRNNRxm4rVPUgSyZauV6nNe+drL6uPldP70OC2xVqpCHhtI5O7VYL6nyjXzGSFtt/zCzMjJFlabpFVOKfiEz462xBBk8M7tcW+PSfc9B1CYS/lX0W6yNtrqBgJ7iTOZ7I+QTEDg5Vq+KnuUoJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780073010; c=relaxed/simple; bh=J1Eb26yXzGpOf2bgrVjU6dUVb9eUDnHPNte+iAlMmLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f9Hyo2XZuEKKN9+1pb6IkHol4EuoosoDVXIYljuH2bt1GpZfYa/Sbmabm5qkkmjyBGmoIDS8bXTX25q6+fLOgP1TPlIWsQhGowh2mGbRwU6wsXAMQBmbmP7bRCk2Q1PBtpsMq+toKp2uSavnFsqkk19dgFJSOALH+YD9zD6+VhQ= 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=mSH53gdk; 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="mSH53gdk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1780073004; bh=J1Eb26yXzGpOf2bgrVjU6dUVb9eUDnHPNte+iAlMmLM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mSH53gdkqSpv4X1B2VQMbWd0w7KaaKINh42jPHPA5JzkqIus+9YnGA5fBXjL5cTmP U5heXBe5jmjB/Wx/fPc5dmENS87VCJD0sGi2d+1PQuupnswvx5AzvJcg0i9l+/gfXI 4bsAVUh7xSUYP+XT23dN8HOho1fkeWGyB2LSUc1g= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 29 May 2026 18:43:22 +0200 Subject: [PATCH 1/4] kobject: Provide macros to initialize 'struct kobj_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: <20260529-sysfs-const-attr-kobj-attr-prep-v1-1-7e667ba3bb85@weissschuh.net> References: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> In-Reply-To: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Andrew Morton Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780073003; l=1650; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=J1Eb26yXzGpOf2bgrVjU6dUVb9eUDnHPNte+iAlMmLM=; b=SGzVSFaheSzcJz/KidztYGzagWXTO5b7FdgN2HAKYwu8GvuGFBee8+AAKgn/yQbMzjC3lUVMV z1YG2Uv3We8B0MJhOfRZ6dTm4dMAKweRCFPoWYjzfPLtao38ZRVt9xu X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Currently the generic __ATTR*() macros are used to initialize kobject attributes. These are not able to handle the upcoming piece-by-piece constification of the attribute callback handlers. Add dedicated macros of kobject attributes. For now these are the same as the generic macros, but they will change soon. Users will be converted to these macros as part of the constification, but it is expected that they will be used generally in the future. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/kobject.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index bcb5d4e32001..975a5361fb60 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -144,6 +144,28 @@ struct kobj_attribute { const char *buf, size_t count); }; =20 +#define __KOBJ_ATTR(_name, _mode, _show, _store) { \ + .attr =3D { .name =3D __stringify(_name), \ + .mode =3D VERIFY_OCTAL_PERMISSIONS(_mode) }, \ + .show =3D _show, \ + .store =3D _store, \ +} + +#define __KOBJ_ATTR_RO_MODE(_name, _mode) { \ + __KOBJ_ATTR(_name, _mode, _name##_show, NULL) + +#define __KOBJ_ATTR_RO(_name) \ + __KOBJ_ATTR_RO_MODE(_name, 0444) + +#define __KOBJ_ATTR_RW_MODE(_name, _mode) \ + __KOBJ_ATTR(_name, _mode, _name##_show, _name##_store) + +#define __KOBJ_ATTR_WO(_name) \ + __KOBJ_ATTR(_name, 0200, NULL, _name##_store) + +#define __KOBJ_ATTR_RW(_name) \ + __KOBJ_ATTR(_name, 0644, _name##_show, _name##_store) + extern const struct sysfs_ops kobj_sysfs_ops; =20 struct sock; --=20 2.54.0 From nobody Mon Jun 8 11:02:09 2026 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 873563EFFB8 for ; Fri, 29 May 2026 16:43: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=1780073008; cv=none; b=mAa6NPYsuhziyQaoYB8S+wJLURm0y9l9Nz9c1Pl39UfNeMtrFWrP/hzyMfRSDhXXmy37CitIkezAOMtbRwCwcVgTVv9LSOBwtUiyLKlyOFgsZ7Pi90a18BTrHMzXu+/DDf7N4couf2u03SgkLGug5nrxPMfKhRHAn+LqtNty/Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780073008; c=relaxed/simple; bh=UpJEjdW7e+Vs5I6IEAp6beaEYGVO5R99giEVIWQd2gY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eRlY7GOjMWUbibs/QZyq2Gc0iIYVGqiQgv1jrL5PWRsZ2+CkHU6rzucsSxjQs2+veh5WKx2skVPkmRYcM3CFxspdgSZpo+46rKwuJ97YCEEr+65/T61OkoL6vgM0q6IodNKBDY+4f0wXz9XNI2+9tTMkHzsSDD35XjC4LUHlE00= 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=E3CQEeuy; 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="E3CQEeuy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1780073004; bh=UpJEjdW7e+Vs5I6IEAp6beaEYGVO5R99giEVIWQd2gY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=E3CQEeuy0Crlg1Q9n7HoNOoEGrRZJOWmimqd5NCExqVC4pKLolKb1FE8g8nzDXFlF 1ybanALk9xUG4TP5A5RfylDrWCq+1PPYVNnbcgevY0qHY8itGXRjzGYTpfpsFCdJWq 8kwo0GOmx1kaUADEaADzr3oropPFWXb2nJ6jpY3w= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 29 May 2026 18:43:23 +0200 Subject: [PATCH 2/4] samples/kobject: Switch to the new __KOBJ_ATTR() macro 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: <20260529-sysfs-const-attr-kobj-attr-prep-v1-2-7e667ba3bb85@weissschuh.net> References: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> In-Reply-To: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Andrew Morton Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780073003; l=1249; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=UpJEjdW7e+Vs5I6IEAp6beaEYGVO5R99giEVIWQd2gY=; b=vfuOIkVY3LhMODM5axtu6fVPWg8XwSiWlMaL0LcbMkBvOz6TNl++J4nVdq3M4WIvCOJhbX6W8 +/g96PQ0S74AZle3uV/Bu181Aqqd1hZnF8M6eqLOl7chyRkrzcZzpAU X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= To demonstrate and test the upcoming 'const struct kobj_attribute' handling, convert the sample to the new macro. Signed-off-by: Thomas Wei=C3=9Fschuh --- samples/kobject/kobject-example.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-ex= ample.c index 36d87ca0bee2..7404f310dc45 100644 --- a/samples/kobject/kobject-example.c +++ b/samples/kobject/kobject-example.c @@ -45,7 +45,7 @@ static ssize_t foo_store(struct kobject *kobj, struct kob= j_attribute *attr, =20 /* Sysfs attributes cannot be world-writable. */ static struct kobj_attribute foo_attribute =3D - __ATTR(foo, 0664, foo_show, foo_store); + __KOBJ_ATTR(foo, 0664, foo_show, foo_store); =20 /* * More complex function where we determine which variable is being access= ed by @@ -80,9 +80,9 @@ static ssize_t b_store(struct kobject *kobj, struct kobj_= attribute *attr, } =20 static struct kobj_attribute baz_attribute =3D - __ATTR(baz, 0664, b_show, b_store); + __KOBJ_ATTR(baz, 0664, b_show, b_store); static struct kobj_attribute bar_attribute =3D - __ATTR(bar, 0664, b_show, b_store); + __KOBJ_ATTR(bar, 0664, b_show, b_store); =20 =20 /* --=20 2.54.0 From nobody Mon Jun 8 11:02:09 2026 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 B2D003F0A81 for ; Fri, 29 May 2026 16:43: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=1780073008; cv=none; b=r5IwKgDXtj4LJd3msWqjfDZzeE2ZrHVu84LSq7j6JgJRO3hw3Kw5/1834gAaWjYtaS2G+bNXXo6bbVLKN+gv3gZi2cFv/VkWTASBTXYyGQeRGpcgut3AVuVkrZvpTkLXZ7thoWRvGSRYTQyFZ4rwDccmJslQ15LTXJhDC47OnKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780073008; c=relaxed/simple; bh=8WHvFnmK59Pi+8HXymoZgMJLRoy9RphqyWEgcwvTl9M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gQxuR21f+EVIGrAI6O+sCX54WB1aq0nw11VWbU6x7xZlluVxyM7GH3SrdVSXnhRjFvC0CNG84UCzw7jXDwaRTJk5p565z9Dx4a1VslKruDUmtYs0ux1t9XT1f1N7zflkg61qS6z5iygUyuGVULE3FgxQUqlORZ1phJ3AMT9gVaU= 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=jeNsraOu; 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="jeNsraOu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1780073004; bh=8WHvFnmK59Pi+8HXymoZgMJLRoy9RphqyWEgcwvTl9M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jeNsraOuoJWAdd9976rDYDwWDrsLqjdj/+rR95xaomKRUzMMXQW+J5NF1eNXLtEV6 b6relZJlrhVKFblbjh0ptflynUVK1LMW0j7T6updUFaxG2dKJ54SBFEIjtwLTXopjY DzC/2DZKn35au2//cHHcuKmFzlpsbaA4CSD4kULM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 29 May 2026 18:43:24 +0200 Subject: [PATCH 3/4] kobject: Allow the constification of kobject attributes 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: <20260529-sysfs-const-attr-kobj-attr-prep-v1-3-7e667ba3bb85@weissschuh.net> References: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> In-Reply-To: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Andrew Morton Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780073003; l=3985; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=8WHvFnmK59Pi+8HXymoZgMJLRoy9RphqyWEgcwvTl9M=; b=kKE+EWUd9U9jOjxESVGnkoYeNJV6tax2pnUBL+W/l0y9ZdREzo9S8RlPnkyhUuWE2O8aj08LJ HetixVdgjJNDD0rzw9vwZdTOS85VyTcltgRew+wsOns4K/WXV3klImi X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Allow kobject attribute to reside in read-only memory. Both const and non-const attributes are handled by the utility macros and attributes can be migrated one-by-one. Signed-off-by: Thomas Wei=C3=9Fschuh --- include/linux/kobject.h | 57 +++++++++++++++++++++++++++++++++++++++++++--= ---- lib/kobject.c | 8 +++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 975a5361fb60..2c5b386d441c 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -138,17 +138,62 @@ struct kset_uevent_ops { =20 struct kobj_attribute { struct attribute attr; - ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, - char *buf); - ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, - const char *buf, size_t count); + __SYSFS_FUNCTION_ALTERNATIVE( + ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char = *buf); + ssize_t (*show_const)(struct kobject *kobj, const struct kobj_attribute = *attr, + char *buf); + ); + __SYSFS_FUNCTION_ALTERNATIVE( + ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count); + ssize_t (*store_const)(struct kobject *kobj, const struct kobj_attribute= *attr, + const char *buf, size_t count); + ); }; =20 +typedef ssize_t __kobj_show_handler_const(struct kobject *kobj, const stru= ct kobj_attribute *attr, + char *buf); +typedef ssize_t __kobj_store_handler_const(struct kobject *kobj, const str= uct kobj_attribute *attr, + const char *buf, size_t count); + +#ifdef CONFIG_CFI + +#define __KOBJ_ATTR_SHOW_STORE(_show, _store) \ + .show =3D _Generic(_show, \ + __kobj_show_handler_const * : NULL, \ + default : _show \ + ), \ + .show_const =3D _Generic(_show, \ + __kobj_show_handler_const * : _show, \ + default : NULL \ + ), \ + .store =3D _Generic(_store, \ + __kobj_store_handler_const * : NULL, \ + default : _store \ + ), \ + .store_const =3D _Generic(_store, \ + __kobj_store_handler_const * : _store, \ + default : NULL \ + ), + +#else + +#define __KOBJ_ATTR_SHOW_STORE(_show, _store) \ + .show =3D _Generic(_show, \ + __kobj_show_handler_const * : (void *)_show, \ + default : _show \ + ), \ + .store =3D _Generic(_store, \ + __kobj_store_handler_const * : (void *)_store, \ + default : _store \ + ), \ + +#endif + #define __KOBJ_ATTR(_name, _mode, _show, _store) { \ .attr =3D { .name =3D __stringify(_name), \ .mode =3D VERIFY_OCTAL_PERMISSIONS(_mode) }, \ - .show =3D _show, \ - .store =3D _store, \ + __KOBJ_ATTR_SHOW_STORE(_show, _store) \ } =20 #define __KOBJ_ATTR_RO_MODE(_name, _mode) { \ diff --git a/lib/kobject.c b/lib/kobject.c index 9c9ff0f5175f..e7b010a989fb 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -823,9 +823,11 @@ static ssize_t kobj_attr_show(struct kobject *kobj, st= ruct attribute *attr, struct kobj_attribute *kattr; ssize_t ret =3D -EIO; =20 - kattr =3D container_of(attr, struct kobj_attribute, attr); + kattr =3D container_of_const(attr, struct kobj_attribute, attr); if (kattr->show) ret =3D kattr->show(kobj, kattr, buf); + else if (kattr->show_const) + ret =3D kattr->show_const(kobj, kattr, buf); return ret; } =20 @@ -835,9 +837,11 @@ static ssize_t kobj_attr_store(struct kobject *kobj, s= truct attribute *attr, struct kobj_attribute *kattr; ssize_t ret =3D -EIO; =20 - kattr =3D container_of(attr, struct kobj_attribute, attr); + kattr =3D container_of_const(attr, struct kobj_attribute, attr); if (kattr->store) ret =3D kattr->store(kobj, kattr, buf, count); + else if (kattr->store_const) + ret =3D kattr->store_const(kobj, kattr, buf, count); return ret; } =20 --=20 2.54.0 From nobody Mon Jun 8 11:02:09 2026 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 871E33EFD35 for ; Fri, 29 May 2026 16:43: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=1780073008; cv=none; b=g1wIF77nZfZZ8ghLW2BI7rBaXV+hEjVAbeAr/bjlW+dKUhOyCDg9oGbQgW4SqjbLk/llMTTDEDukk3kOABeklZd92TwP2SpQd2DivELCxT9hJp7/kIHDXPgQ4057t1Vdo+WuoI5nb6vaU7jsogv1ld652R/GIJE44WfArSaatWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780073008; c=relaxed/simple; bh=OdyDyu8p7T0rithrC0nFg9HevDkps7Fr1U3EVm4fg6U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JVTH5nCCyVcbvD/iFFLzC0y1Dz8aCiRt7krG9WTmEf/sJBJ6TusdF3VZIxaZE5jok4FyTJZOclKmmIFHM5B2NwT+LP62u8TKIPLuPJ5LBY9CNdUHvyMsPzg93mPWe8+Bla+rEDIwnWIYQaKJbBg5Gd4B/OPjZsuvugS8pq5VsCk= 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=gxLDWAth; 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="gxLDWAth" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1780073004; bh=OdyDyu8p7T0rithrC0nFg9HevDkps7Fr1U3EVm4fg6U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gxLDWAthp6raQlDCbuVUCHw8h2NS2WDGU4FPfm3C1vpXDmO32tmb8Dlkw/I0Eeab0 SgFdlN/lDGDiHA1/DWCG5NghI2zCv0GcInF1xy5dfYT1SRVfYPTgPrHATn/5YzBfas Kdw/V21TYr/dqlxYdM/g5z+ygl9cH/musZaeEnxw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Fri, 29 May 2026 18:43:25 +0200 Subject: [PATCH 4/4] samples/kobject: Constify kobject attributes 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: <20260529-sysfs-const-attr-kobj-attr-prep-v1-4-7e667ba3bb85@weissschuh.net> References: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> In-Reply-To: <20260529-sysfs-const-attr-kobj-attr-prep-v1-0-7e667ba3bb85@weissschuh.net> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Andrew Morton Cc: driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780073003; l=3025; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=OdyDyu8p7T0rithrC0nFg9HevDkps7Fr1U3EVm4fg6U=; b=bvv4AQI1JttYsaf53S5ld329jS89YUq3g8/D6bw2eR2agP/lT5AvhI9KJUAWXx35S6RN68g7T EIswVTu+Z4ADzEMIaxNlgAreHn2mgVMBIi57d+1USpzc1dSbTtcwD6u X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= Demonstrate that 'const struct kobj_attribute' is now supported by the kobject core. Signed-off-by: Thomas Wei=C3=9Fschuh --- samples/kobject/kobject-example.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-ex= ample.c index 7404f310dc45..36f3fbc47fe0 100644 --- a/samples/kobject/kobject-example.c +++ b/samples/kobject/kobject-example.c @@ -25,13 +25,13 @@ static int bar; /* * The "foo" file where a static variable is read from and written to. */ -static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, +static ssize_t foo_show(struct kobject *kobj, const struct kobj_attribute = *attr, char *buf) { return sysfs_emit(buf, "%d\n", foo); } =20 -static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, +static ssize_t foo_store(struct kobject *kobj, const struct kobj_attribute= *attr, const char *buf, size_t count) { int ret; @@ -44,14 +44,14 @@ static ssize_t foo_store(struct kobject *kobj, struct k= obj_attribute *attr, } =20 /* Sysfs attributes cannot be world-writable. */ -static struct kobj_attribute foo_attribute =3D +static const struct kobj_attribute foo_attribute =3D __KOBJ_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 kobject *kobj, struct kobj_attribute *attr, +static ssize_t b_show(struct kobject *kobj, const struct kobj_attribute *a= ttr, char *buf) { int var; @@ -63,7 +63,7 @@ static ssize_t b_show(struct kobject *kobj, struct kobj_a= ttribute *attr, return sysfs_emit(buf, "%d\n", var); } =20 -static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, +static ssize_t b_store(struct kobject *kobj, const struct kobj_attribute *= attr, const char *buf, size_t count) { int var, ret; @@ -79,9 +79,9 @@ static ssize_t b_store(struct kobject *kobj, struct kobj_= attribute *attr, return count; } =20 -static struct kobj_attribute baz_attribute =3D +static const struct kobj_attribute baz_attribute =3D __KOBJ_ATTR(baz, 0664, b_show, b_store); -static struct kobj_attribute bar_attribute =3D +static const struct kobj_attribute bar_attribute =3D __KOBJ_ATTR(bar, 0664, b_show, b_store); =20 =20 @@ -89,7 +89,7 @@ static struct kobj_attribute bar_attribute =3D * Create a group of attributes so that we can create and destroy them all * at once. */ -static struct attribute *attrs[] =3D { +static const struct attribute *const attrs[] =3D { &foo_attribute.attr, &baz_attribute.attr, &bar_attribute.attr, @@ -103,7 +103,7 @@ static struct attribute *attrs[] =3D { * attribute group. */ static const struct attribute_group attr_group =3D { - .attrs =3D attrs, + .attrs_const =3D attrs, }; =20 static struct kobject *example_kobj; --=20 2.54.0