public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 00/10] driver core: constify groups arrays in several structs
@ 2026-02-17 22:24 Heiner Kallweit
  2026-02-17 22:25 ` [PATCH RFC 01/10] IB/core: Prepare for immutable device groups Heiner Kallweit
                   ` (9 more replies)
  0 siblings, 10 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:24 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

This series constifies the attribute group groups arrays in a number
of structs, plus some preparation work. This allows to assign constant
arrays, w/o "discards const qualifier" compiler warning.
This is a step towards to goal to e.g. create constant arrays in macro
__ATTRIBUTE_GROUPS().

There may be drivers not covered by my test scenarios which conflict
with this series. Therefore I send it as RFC for now.
Hopefully some CI checking this series provides additional hints.

Heiner Kallweit (10):
  IB/core: Prepare for immutable device groups
  rtc: prepare for struct device member groups becoming a constant array
  sysfs: constify group arrays in function arguments
  driver: core: constify groups array argument in device_add_groups and
    device_remove_groups
  driver core: make struct device member groups a constant array
  driver core: make struct device_type member groups a constant array
  driver core: make struct bus_type groups members constant arrays
  driver core: make struct class groups members constant arrays
  driver core: make struct device_driver groups members contact arrays
  kobject: make struct kobject member default_groups a constant array

 drivers/base/base.h              |  6 ++++--
 drivers/base/core.c              |  5 +++--
 drivers/base/driver.c            |  4 ++--
 drivers/infiniband/core/device.c |  9 ++++-----
 drivers/rtc/sysfs.c              |  8 ++++----
 fs/sysfs/group.c                 | 10 +++++-----
 include/linux/device.h           |  8 ++++----
 include/linux/device/bus.h       |  6 +++---
 include/linux/device/class.h     |  4 ++--
 include/linux/device/driver.h    |  4 ++--
 include/linux/kobject.h          |  2 +-
 include/linux/sysfs.h            | 16 ++++++++--------
 12 files changed, 42 insertions(+), 40 deletions(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH RFC 01/10] IB/core: Prepare for immutable device groups
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
@ 2026-02-17 22:25 ` Heiner Kallweit
  2026-02-18  8:54   ` Leon Romanovsky
  2026-02-17 22:26 ` [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array Heiner Kallweit
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:25 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

This prepares for making struct device member groups a constant array.
No functional change intended.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/infiniband/core/device.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 1174ab7da62..f967ad534fc 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -565,15 +565,14 @@ static void rdma_init_coredev(struct ib_core_device *coredev,
 	 */
 	BUILD_BUG_ON(offsetof(struct ib_device, coredev.dev) !=
 		     offsetof(struct ib_device, dev));
-
-	coredev->dev.class = &ib_class;
-	coredev->dev.groups = dev->groups;
-
 	/*
 	 * Don't expose hw counters outside of the init namespace.
 	 */
 	if (!is_full_dev && dev->hw_stats_attr_index)
-		coredev->dev.groups[dev->hw_stats_attr_index] = NULL;
+		dev->groups[dev->hw_stats_attr_index] = NULL;
+
+	coredev->dev.class = &ib_class;
+	coredev->dev.groups = dev->groups;
 
 	device_initialize(&coredev->dev);
 	coredev->owner = dev;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
  2026-02-17 22:25 ` [PATCH RFC 01/10] IB/core: Prepare for immutable device groups Heiner Kallweit
@ 2026-02-17 22:26 ` Heiner Kallweit
  2026-02-19  0:53   ` yanjun.zhu
  2026-02-17 22:27 ` [PATCH RFC 03/10] sysfs: constify group arrays in function arguments Heiner Kallweit
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:26 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

This prepares for making struct device member groups a constant array.
The assignment groups = rtc->dev.groups would result in a "discarding
const qualifier" warning with this change.
No functional change intended.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/rtc/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
index 4ab05e105a7..ae5e1252b4c 100644
--- a/drivers/rtc/sysfs.c
+++ b/drivers/rtc/sysfs.c
@@ -308,7 +308,7 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void)
 int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
 {
 	size_t old_cnt = 0, add_cnt = 0, new_cnt;
-	const struct attribute_group **groups, **old;
+	const struct attribute_group **groups, *const *old;
 
 	if (grps) {
 		for (groups = grps; *groups; groups++)
@@ -320,9 +320,9 @@ int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
 		return -EINVAL;
 	}
 
-	groups = rtc->dev.groups;
-	if (groups)
-		for (; *groups; groups++)
+	old = rtc->dev.groups;
+	if (old)
+		while (*old++)
 			old_cnt++;
 
 	new_cnt = old_cnt + add_cnt + 1;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 03/10] sysfs: constify group arrays in function arguments
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
  2026-02-17 22:25 ` [PATCH RFC 01/10] IB/core: Prepare for immutable device groups Heiner Kallweit
  2026-02-17 22:26 ` [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array Heiner Kallweit
@ 2026-02-17 22:27 ` Heiner Kallweit
  2026-02-17 22:28 ` [PATCH RFC 04/10] driver: core: constify groups array argument in device_add_groups and device_remove_groups Heiner Kallweit
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:27 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the groups array argument where applicable. This allows to
pass constant arrays as arguments.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 fs/sysfs/group.c      | 10 +++++-----
 include/linux/sysfs.h | 16 ++++++++--------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index e1e639f515a..b3edae0578c 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -217,7 +217,7 @@ int sysfs_create_group(struct kobject *kobj,
 EXPORT_SYMBOL_GPL(sysfs_create_group);
 
 static int internal_create_groups(struct kobject *kobj, int update,
-				  const struct attribute_group **groups)
+				  const struct attribute_group *const *groups)
 {
 	int error = 0;
 	int i;
@@ -250,7 +250,7 @@ static int internal_create_groups(struct kobject *kobj, int update,
  * Returns 0 on success or error code from sysfs_create_group on failure.
  */
 int sysfs_create_groups(struct kobject *kobj,
-			const struct attribute_group **groups)
+			const struct attribute_group *const *groups)
 {
 	return internal_create_groups(kobj, 0, groups);
 }
@@ -268,7 +268,7 @@ EXPORT_SYMBOL_GPL(sysfs_create_groups);
  * Returns 0 on success or error code from sysfs_update_group on failure.
  */
 int sysfs_update_groups(struct kobject *kobj,
-			const struct attribute_group **groups)
+			const struct attribute_group *const *groups)
 {
 	return internal_create_groups(kobj, 1, groups);
 }
@@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(sysfs_remove_group);
  * If groups is not NULL, remove the specified groups from the kobject.
  */
 void sysfs_remove_groups(struct kobject *kobj,
-			 const struct attribute_group **groups)
+			 const struct attribute_group *const *groups)
 {
 	int i;
 
@@ -613,7 +613,7 @@ EXPORT_SYMBOL_GPL(sysfs_group_change_owner);
  * Returns 0 on success or error code on failure.
  */
 int sysfs_groups_change_owner(struct kobject *kobj,
-			      const struct attribute_group **groups,
+			      const struct attribute_group *const *groups,
 			      kuid_t kuid, kgid_t kgid)
 {
 	int error = 0, i;
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index c33a96b7391..445869ce0f4 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -445,15 +445,15 @@ void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
 int __must_check sysfs_create_group(struct kobject *kobj,
 				    const struct attribute_group *grp);
 int __must_check sysfs_create_groups(struct kobject *kobj,
-				     const struct attribute_group **groups);
+				     const struct attribute_group *const *groups);
 int __must_check sysfs_update_groups(struct kobject *kobj,
-				     const struct attribute_group **groups);
+				     const struct attribute_group *const *groups);
 int sysfs_update_group(struct kobject *kobj,
 		       const struct attribute_group *grp);
 void sysfs_remove_group(struct kobject *kobj,
 			const struct attribute_group *grp);
 void sysfs_remove_groups(struct kobject *kobj,
-			 const struct attribute_group **groups);
+			 const struct attribute_group *const *groups);
 int sysfs_add_file_to_group(struct kobject *kobj,
 			const struct attribute *attr, const char *group);
 void sysfs_remove_file_from_group(struct kobject *kobj,
@@ -486,7 +486,7 @@ int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid);
 int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ,
 			    const char *name, kuid_t kuid, kgid_t kgid);
 int sysfs_groups_change_owner(struct kobject *kobj,
-			      const struct attribute_group **groups,
+			      const struct attribute_group *const *groups,
 			      kuid_t kuid, kgid_t kgid);
 int sysfs_group_change_owner(struct kobject *kobj,
 			     const struct attribute_group *groups, kuid_t kuid,
@@ -629,13 +629,13 @@ static inline int sysfs_create_group(struct kobject *kobj,
 }
 
 static inline int sysfs_create_groups(struct kobject *kobj,
-				      const struct attribute_group **groups)
+				      const struct attribute_group *const *groups)
 {
 	return 0;
 }
 
 static inline int sysfs_update_groups(struct kobject *kobj,
-				      const struct attribute_group **groups)
+				      const struct attribute_group *const *groups)
 {
 	return 0;
 }
@@ -652,7 +652,7 @@ static inline void sysfs_remove_group(struct kobject *kobj,
 }
 
 static inline void sysfs_remove_groups(struct kobject *kobj,
-				       const struct attribute_group **groups)
+				       const struct attribute_group *const *groups)
 {
 }
 
@@ -733,7 +733,7 @@ static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t k
 }
 
 static inline int sysfs_groups_change_owner(struct kobject *kobj,
-			  const struct attribute_group **groups,
+			  const struct attribute_group *const *groups,
 			  kuid_t kuid, kgid_t kgid)
 {
 	return 0;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 04/10] driver: core: constify groups array argument in device_add_groups and device_remove_groups
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (2 preceding siblings ...)
  2026-02-17 22:27 ` [PATCH RFC 03/10] sysfs: constify group arrays in function arguments Heiner Kallweit
@ 2026-02-17 22:28 ` Heiner Kallweit
  2026-02-17 22:28 ` [PATCH RFC 05/10] driver core: make struct device member groups a constant array Heiner Kallweit
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:28 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Now that sysfs_create_groups() and sysfs_remove_groups() allow to
pass constant groups arrays, we can constify the groups array argument
also here.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/base/core.c    | 5 +++--
 include/linux/device.h | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index f599a1384ee..4db63b2603c 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2831,14 +2831,15 @@ static ssize_t removable_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(removable);
 
-int device_add_groups(struct device *dev, const struct attribute_group **groups)
+int device_add_groups(struct device *dev,
+		      const struct attribute_group *const *groups)
 {
 	return sysfs_create_groups(&dev->kobj, groups);
 }
 EXPORT_SYMBOL_GPL(device_add_groups);
 
 void device_remove_groups(struct device *dev,
-			  const struct attribute_group **groups)
+			  const struct attribute_group *const *groups)
 {
 	sysfs_remove_groups(&dev->kobj, groups);
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 0be95294b6e..48a0444ccc1 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1131,9 +1131,9 @@ device_create_with_groups(const struct class *cls, struct device *parent, dev_t
 void device_destroy(const struct class *cls, dev_t devt);
 
 int __must_check device_add_groups(struct device *dev,
-				   const struct attribute_group **groups);
+				   const struct attribute_group *const *groups);
 void device_remove_groups(struct device *dev,
-			  const struct attribute_group **groups);
+			  const struct attribute_group *const *groups);
 
 static inline int __must_check device_add_group(struct device *dev,
 					const struct attribute_group *grp)
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 05/10] driver core: make struct device member groups a constant array
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (3 preceding siblings ...)
  2026-02-17 22:28 ` [PATCH RFC 04/10] driver: core: constify groups array argument in device_add_groups and device_remove_groups Heiner Kallweit
@ 2026-02-17 22:28 ` Heiner Kallweit
  2026-02-17 22:29 ` [PATCH RFC 06/10] driver core: make struct device_type " Heiner Kallweit
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:28 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the groups array, allowing to assign constant arrays.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 include/linux/device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index 48a0444ccc1..bfa2ca603c2 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -640,7 +640,7 @@ struct device {
 	struct list_head	devres_head;
 
 	const struct class	*class;
-	const struct attribute_group **groups;	/* optional groups */
+	const struct attribute_group *const *groups;	/* optional groups */
 
 	void	(*release)(struct device *dev);
 	struct iommu_group	*iommu_group;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 06/10] driver core: make struct device_type member groups a constant array
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (4 preceding siblings ...)
  2026-02-17 22:28 ` [PATCH RFC 05/10] driver core: make struct device member groups a constant array Heiner Kallweit
@ 2026-02-17 22:29 ` Heiner Kallweit
  2026-02-17 22:30 ` [PATCH RFC 07/10] driver core: make struct bus_type groups members constant arrays Heiner Kallweit
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:29 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the groups array, allowing to assign constant arrays.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 include/linux/device.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index bfa2ca603c2..808f723bbcf 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -87,7 +87,7 @@ int subsys_virtual_register(const struct bus_type *subsys,
  */
 struct device_type {
 	const char *name;
-	const struct attribute_group **groups;
+	const struct attribute_group *const *groups;
 	int (*uevent)(const struct device *dev, struct kobj_uevent_env *env);
 	char *(*devnode)(const struct device *dev, umode_t *mode,
 			 kuid_t *uid, kgid_t *gid);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 07/10] driver core: make struct bus_type groups members constant arrays
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (5 preceding siblings ...)
  2026-02-17 22:29 ` [PATCH RFC 06/10] driver core: make struct device_type " Heiner Kallweit
@ 2026-02-17 22:30 ` Heiner Kallweit
  2026-02-17 22:30 ` [PATCH RFC 08/10] driver core: make struct class " Heiner Kallweit
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:30 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the groupss arrays, allowing to assign constant arrays.
As a prerequisite this requires to constify the groups array argument
in few functions.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/base/base.h        | 6 ++++--
 drivers/base/driver.c      | 4 ++--
 include/linux/device/bus.h | 6 +++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 8c2175820da..b6852ba45cd 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -202,8 +202,10 @@ static inline void dev_sync_state(struct device *dev)
 		dev->driver->sync_state(dev);
 }
 
-int driver_add_groups(const struct device_driver *drv, const struct attribute_group **groups);
-void driver_remove_groups(const struct device_driver *drv, const struct attribute_group **groups);
+int driver_add_groups(const struct device_driver *drv,
+		      const struct attribute_group *const *groups);
+void driver_remove_groups(const struct device_driver *drv,
+			  const struct attribute_group *const *groups);
 void device_driver_detach(struct device *dev);
 
 static inline void device_set_driver(struct device *dev, const struct device_driver *drv)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 8ab010ddf70..c5ebf1fdad7 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -203,13 +203,13 @@ void driver_remove_file(const struct device_driver *drv,
 EXPORT_SYMBOL_GPL(driver_remove_file);
 
 int driver_add_groups(const struct device_driver *drv,
-		      const struct attribute_group **groups)
+		      const struct attribute_group *const *groups)
 {
 	return sysfs_create_groups(&drv->p->kobj, groups);
 }
 
 void driver_remove_groups(const struct device_driver *drv,
-			  const struct attribute_group **groups)
+			  const struct attribute_group *const *groups)
 {
 	sysfs_remove_groups(&drv->p->kobj, groups);
 }
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index 99c3c83ea52..00d8a080f93 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -78,9 +78,9 @@ struct fwnode_handle;
 struct bus_type {
 	const char		*name;
 	const char		*dev_name;
-	const struct attribute_group **bus_groups;
-	const struct attribute_group **dev_groups;
-	const struct attribute_group **drv_groups;
+	const struct attribute_group *const *bus_groups;
+	const struct attribute_group *const *dev_groups;
+	const struct attribute_group *const *drv_groups;
 
 	int (*match)(struct device *dev, const struct device_driver *drv);
 	int (*uevent)(const struct device *dev, struct kobj_uevent_env *env);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 08/10] driver core: make struct class groups members constant arrays
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (6 preceding siblings ...)
  2026-02-17 22:30 ` [PATCH RFC 07/10] driver core: make struct bus_type groups members constant arrays Heiner Kallweit
@ 2026-02-17 22:30 ` Heiner Kallweit
  2026-02-17 22:31 ` [PATCH RFC 09/10] driver core: make struct device_driver groups members contact arrays Heiner Kallweit
  2026-02-17 22:32 ` [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array Heiner Kallweit
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:30 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the groups arrays, allowing to assign constant arrays.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 include/linux/device/class.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/device/class.h b/include/linux/device/class.h
index 65880e60c72..2079239a5aa 100644
--- a/include/linux/device/class.h
+++ b/include/linux/device/class.h
@@ -50,8 +50,8 @@ struct fwnode_handle;
 struct class {
 	const char		*name;
 
-	const struct attribute_group	**class_groups;
-	const struct attribute_group	**dev_groups;
+	const struct attribute_group	*const *class_groups;
+	const struct attribute_group	*const *dev_groups;
 
 	int (*dev_uevent)(const struct device *dev, struct kobj_uevent_env *env);
 	char *(*devnode)(const struct device *dev, umode_t *mode);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 09/10] driver core: make struct device_driver groups members contact arrays
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (7 preceding siblings ...)
  2026-02-17 22:30 ` [PATCH RFC 08/10] driver core: make struct class " Heiner Kallweit
@ 2026-02-17 22:31 ` Heiner Kallweit
  2026-02-17 22:32 ` [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array Heiner Kallweit
  9 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:31 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the groups arrays, allowing to assign constant arrays.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 include/linux/device/driver.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h
index bbc67ec513e..c882daaef01 100644
--- a/include/linux/device/driver.h
+++ b/include/linux/device/driver.h
@@ -114,8 +114,8 @@ struct device_driver {
 	void (*shutdown) (struct device *dev);
 	int (*suspend) (struct device *dev, pm_message_t state);
 	int (*resume) (struct device *dev);
-	const struct attribute_group **groups;
-	const struct attribute_group **dev_groups;
+	const struct attribute_group *const *groups;
+	const struct attribute_group *const *dev_groups;
 
 	const struct dev_pm_ops *pm;
 	void (*coredump) (struct device *dev);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array
  2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
                   ` (8 preceding siblings ...)
  2026-02-17 22:31 ` [PATCH RFC 09/10] driver core: make struct device_driver groups members contact arrays Heiner Kallweit
@ 2026-02-17 22:32 ` Heiner Kallweit
  2026-02-21 13:27   ` Thomas Weißschuh
  9 siblings, 1 reply; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-17 22:32 UTC (permalink / raw)
  To: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Leon Romanovsky,
	Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

Constify the default_groups array, allowing to assign constant arrays.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 include/linux/kobject.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index c8219505a79..e45ee843931 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -116,7 +116,7 @@ char *kobject_get_path(const struct kobject *kobj, gfp_t flag);
 struct kobj_type {
 	void (*release)(struct kobject *kobj);
 	const struct sysfs_ops *sysfs_ops;
-	const struct attribute_group **default_groups;
+	const struct attribute_group *const *default_groups;
 	const struct kobj_ns_type_operations *(*child_ns_type)(const struct kobject *kobj);
 	const void *(*namespace)(const struct kobject *kobj);
 	void (*get_ownership)(const struct kobject *kobj, kuid_t *uid, kgid_t *gid);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 01/10] IB/core: Prepare for immutable device groups
  2026-02-17 22:25 ` [PATCH RFC 01/10] IB/core: Prepare for immutable device groups Heiner Kallweit
@ 2026-02-18  8:54   ` Leon Romanovsky
  0 siblings, 0 replies; 16+ messages in thread
From: Leon Romanovsky @ 2026-02-18  8:54 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Thomas Weißschuh, Greg Kroah-Hartman, Rafael J. Wysocki,
	Danilo Krummrich, Jason Gunthorpe, Alexandre Belloni, driver-core,
	Linux Kernel Mailing List, linux-rdma, linux-rtc

On Tue, Feb 17, 2026 at 11:25:20PM +0100, Heiner Kallweit wrote:
> This prepares for making struct device member groups a constant array.
> No functional change intended.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/infiniband/core/device.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 

Thanks,
Acked-by: Leon Romanovsky <leon@kernel.org>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array
  2026-02-17 22:26 ` [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array Heiner Kallweit
@ 2026-02-19  0:53   ` yanjun.zhu
  2026-02-20 14:38     ` Alexandre Belloni
  0 siblings, 1 reply; 16+ messages in thread
From: yanjun.zhu @ 2026-02-19  0:53 UTC (permalink / raw)
  To: Heiner Kallweit, Thomas Weißschuh, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Jason Gunthorpe,
	Leon Romanovsky, Alexandre Belloni
  Cc: driver-core, Linux Kernel Mailing List, linux-rdma, linux-rtc

On 2/17/26 2:26 PM, Heiner Kallweit wrote:
> This prepares for making struct device member groups a constant array.
> The assignment groups = rtc->dev.groups would result in a "discarding
> const qualifier" warning with this change.
> No functional change intended.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>   drivers/rtc/sysfs.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
> index 4ab05e105a7..ae5e1252b4c 100644
> --- a/drivers/rtc/sysfs.c
> +++ b/drivers/rtc/sysfs.c
> @@ -308,7 +308,7 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void)
>   int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
>   {
>   	size_t old_cnt = 0, add_cnt = 0, new_cnt;
> -	const struct attribute_group **groups, **old;
> +	const struct attribute_group **groups, *const *old;
>   
>   	if (grps) {
>   		for (groups = grps; *groups; groups++)
> @@ -320,9 +320,9 @@ int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
>   		return -EINVAL;
>   	}
>   
> -	groups = rtc->dev.groups;
> -	if (groups)
> -		for (; *groups; groups++)
> +	old = rtc->dev.groups;
> +	if (old)
> +		while (*old++)
>   			old_cnt++;

The change from for (; *groups; groups++) to while (*old++) is not 
functionally equivalent. In the while version, the post-increment old++ 
executes even when *old is NULL. This leaves the pointer old pointing 
one element past the NULL terminator. While old_cnt remains correct, 
this is a side-effect-heavy idiom that differs from standard kernel 
patterns and could be fragile if old is used later in the function.

Best Regards,
Zhu Yanjun

>   
>   	new_cnt = old_cnt + add_cnt + 1;


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array
  2026-02-19  0:53   ` yanjun.zhu
@ 2026-02-20 14:38     ` Alexandre Belloni
  0 siblings, 0 replies; 16+ messages in thread
From: Alexandre Belloni @ 2026-02-20 14:38 UTC (permalink / raw)
  To: yanjun.zhu
  Cc: Heiner Kallweit, Thomas Weißschuh, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, Jason Gunthorpe,
	Leon Romanovsky, driver-core, Linux Kernel Mailing List,
	linux-rdma, linux-rtc

On 18/02/2026 16:53:00-0800, yanjun.zhu wrote:
> On 2/17/26 2:26 PM, Heiner Kallweit wrote:
> > This prepares for making struct device member groups a constant array.
> > The assignment groups = rtc->dev.groups would result in a "discarding
> > const qualifier" warning with this change.
> > No functional change intended.
> > 
> > Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> > ---
> >   drivers/rtc/sysfs.c | 8 ++++----
> >   1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c
> > index 4ab05e105a7..ae5e1252b4c 100644
> > --- a/drivers/rtc/sysfs.c
> > +++ b/drivers/rtc/sysfs.c
> > @@ -308,7 +308,7 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void)
> >   int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
> >   {
> >   	size_t old_cnt = 0, add_cnt = 0, new_cnt;
> > -	const struct attribute_group **groups, **old;
> > +	const struct attribute_group **groups, *const *old;
> >   	if (grps) {
> >   		for (groups = grps; *groups; groups++)
> > @@ -320,9 +320,9 @@ int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps)
> >   		return -EINVAL;
> >   	}
> > -	groups = rtc->dev.groups;
> > -	if (groups)
> > -		for (; *groups; groups++)
> > +	old = rtc->dev.groups;
> > +	if (old)
> > +		while (*old++)
> >   			old_cnt++;
> 
> The change from for (; *groups; groups++) to while (*old++) is not
> functionally equivalent. In the while version, the post-increment old++
> executes even when *old is NULL. This leaves the pointer old pointing one
> element past the NULL terminator. While old_cnt remains correct, this is a
> side-effect-heavy idiom that differs from standard kernel patterns and could
> be fragile if old is used later in the function.
> 

Thanks for pointing this out, I agree we should keep the original for
loop.

With that change,
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>


> Best Regards,
> Zhu Yanjun
> 
> >   	new_cnt = old_cnt + add_cnt + 1;
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array
  2026-02-17 22:32 ` [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array Heiner Kallweit
@ 2026-02-21 13:27   ` Thomas Weißschuh
  2026-02-21 14:04     ` Heiner Kallweit
  0 siblings, 1 reply; 16+ messages in thread
From: Thomas Weißschuh @ 2026-02-21 13:27 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jason Gunthorpe, Leon Romanovsky, Alexandre Belloni, driver-core,
	Linux Kernel Mailing List, linux-rdma, linux-rtc

Hello Heiner,

On 2026-02-17 23:32:46+0100, Heiner Kallweit wrote:
> Constify the default_groups array, allowing to assign constant arrays.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

(The patch author/From header and Signed-off-by line do not match)

> ---
>  include/linux/kobject.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
> index c8219505a79..e45ee843931 100644
> --- a/include/linux/kobject.h
> +++ b/include/linux/kobject.h
> @@ -116,7 +116,7 @@ char *kobject_get_path(const struct kobject *kobj, gfp_t flag);
>  struct kobj_type {
>  	void (*release)(struct kobject *kobj);
>  	const struct sysfs_ops *sysfs_ops;
> -	const struct attribute_group **default_groups;
> +	const struct attribute_group *const *default_groups;

Thanks for working on this!

Personally I try to constify the attribute structures together with
their corresponding callbacks. This ensures that no structure is
constified which its callback then tries to modify.
Currently there is no support for const arguments to the callbacks of
'struct kobj_attribute' and 'struct device_attribute'. I am wondering
if the changes to kobject and device groups should be kept out for now
and be added together with the support for their const callback arguments.


Thomas

>  	const struct kobj_ns_type_operations *(*child_ns_type)(const struct kobject *kobj);
>  	const void *(*namespace)(const struct kobject *kobj);
>  	void (*get_ownership)(const struct kobject *kobj, kuid_t *uid, kgid_t *gid);

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array
  2026-02-21 13:27   ` Thomas Weißschuh
@ 2026-02-21 14:04     ` Heiner Kallweit
  0 siblings, 0 replies; 16+ messages in thread
From: Heiner Kallweit @ 2026-02-21 14:04 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Jason Gunthorpe, Leon Romanovsky, Alexandre Belloni, driver-core,
	Linux Kernel Mailing List, linux-rdma, linux-rtc

On 21.02.2026 14:27, Thomas Weißschuh wrote:
> Hello Heiner,
> 
> On 2026-02-17 23:32:46+0100, Heiner Kallweit wrote:
>> Constify the default_groups array, allowing to assign constant arrays.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> 
> (The patch author/From header and Signed-off-by line do not match)
> 
Right, have to fix this once series is out of RFC state.

>> ---
>>  include/linux/kobject.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
>> index c8219505a79..e45ee843931 100644
>> --- a/include/linux/kobject.h
>> +++ b/include/linux/kobject.h
>> @@ -116,7 +116,7 @@ char *kobject_get_path(const struct kobject *kobj, gfp_t flag);
>>  struct kobj_type {
>>  	void (*release)(struct kobject *kobj);
>>  	const struct sysfs_ops *sysfs_ops;
>> -	const struct attribute_group **default_groups;
>> +	const struct attribute_group *const *default_groups;
> 
> Thanks for working on this!
> 
> Personally I try to constify the attribute structures together with
> their corresponding callbacks. This ensures that no structure is
> constified which its callback then tries to modify.
> Currently there is no support for const arguments to the callbacks of
> 'struct kobj_attribute' and 'struct device_attribute'. I am wondering
> if the changes to kobject and device groups should be kept out for now
> and be added together with the support for their const callback arguments.
> 

I think we have to be precise what exactly gets constified:
In the series here it's about arrays of pointers to attribute groups.
Just these arrays can't be modified any longer. This includes no change
to whether data in the attribute groups and attributes can be modified.

These arrays of pointers to attribute groups are used in calls to
sysfs_create_groups() and device_add_groups(), e.g. from create_dir()
for kobject's, and from device_add_attrs().
And sysfs_create_groups() and device_add_groups() are changed accordingly
in this series.

Does this answer your question?

> 
> Thomas
> 
>>  	const struct kobj_ns_type_operations *(*child_ns_type)(const struct kobject *kobj);
>>  	const void *(*namespace)(const struct kobject *kobj);
>>  	void (*get_ownership)(const struct kobject *kobj, kuid_t *uid, kgid_t *gid);


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-02-21 14:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 22:24 [PATCH RFC 00/10] driver core: constify groups arrays in several structs Heiner Kallweit
2026-02-17 22:25 ` [PATCH RFC 01/10] IB/core: Prepare for immutable device groups Heiner Kallweit
2026-02-18  8:54   ` Leon Romanovsky
2026-02-17 22:26 ` [PATCH RFC 02/10] rtc: prepare for struct device member groups becoming a constant array Heiner Kallweit
2026-02-19  0:53   ` yanjun.zhu
2026-02-20 14:38     ` Alexandre Belloni
2026-02-17 22:27 ` [PATCH RFC 03/10] sysfs: constify group arrays in function arguments Heiner Kallweit
2026-02-17 22:28 ` [PATCH RFC 04/10] driver: core: constify groups array argument in device_add_groups and device_remove_groups Heiner Kallweit
2026-02-17 22:28 ` [PATCH RFC 05/10] driver core: make struct device member groups a constant array Heiner Kallweit
2026-02-17 22:29 ` [PATCH RFC 06/10] driver core: make struct device_type " Heiner Kallweit
2026-02-17 22:30 ` [PATCH RFC 07/10] driver core: make struct bus_type groups members constant arrays Heiner Kallweit
2026-02-17 22:30 ` [PATCH RFC 08/10] driver core: make struct class " Heiner Kallweit
2026-02-17 22:31 ` [PATCH RFC 09/10] driver core: make struct device_driver groups members contact arrays Heiner Kallweit
2026-02-17 22:32 ` [PATCH RFC 10/10] kobject: make struct kobject member default_groups a constant array Heiner Kallweit
2026-02-21 13:27   ` Thomas Weißschuh
2026-02-21 14:04     ` Heiner Kallweit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox