Skip to contentSkip to conversation

driver core: change to_subsys_private() to use container_of_const()

PATCH In review Greg Kroah-Hartman 2 participants 3 messages Jan 11, 2023 Driver core

lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 driver core: change to_subsys_private() to use container_of_const()

The macro to_subsys_private() needs to switch to using container_of_const() as it turned out to being incorrectly casting a const pointer to a non-const one. Make this change and fix up the one offending user to be correctly handling a const pointer properly.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/base.h  | 2 +-
 drivers/base/class.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/base.h +1 -1
index 2e08258ce82e..3d1da1027206 100644
@@ -53,7 +53,7 @@ struct subsys_private {
 	struct kset glue_dirs;
 	struct class *class;
 };
-#define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
+#define to_subsys_private(obj) container_of_const(obj, struct subsys_private, subsys.kobj)
 
 struct driver_private {
 	struct kobject kobj;
drivers/base/class.c +1 -1
index 86ec554cfe60..3366da9c3ff6 100644
@@ -64,7 +64,7 @@ static void class_release(struct kobject *kobj)
 
 static const struct kobj_ns_type_operations *class_child_ns_type(const struct kobject *kobj)
 {
-	struct subsys_private *cp = to_subsys_private(kobj);
+	const struct subsys_private *cp = to_subsys_private(kobj);
 	struct class *class = cp->class;
 
 	return class->ns_type;
Signature · 1 line
2.39.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Greg Kroah-Hartman

The macro to_subsys_private() needs to switch to using container_of_const() as it turned out to being incorrectly casting a const pointer to a non-const one. Make this change and fix up the one offending user to be correctly handling a const pointer properly.

Cc "Rafael J. Wysocki" <[email protected]>
Quoted 34 lines
---
 drivers/base/base.h  | 2 +-
 drivers/base/class.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/base.h +1 -1
index 2e08258ce82e..3d1da1027206 100644
@@ -53,7 +53,7 @@ struct subsys_private {
        struct kset glue_dirs;
        struct class *class;
 };
-#define to_subsys_private(obj) container_of(obj, struct subsys_private, subsys.kobj)
+#define to_subsys_private(obj) container_of_const(obj, struct subsys_private, subsys.kobj)
 
 struct driver_private {
        struct kobject kobj;
drivers/base/class.c +1 -2
index 86ec554cfe60..3366da9c3ff6 100644
@@ -64,7 +64,7 @@ static void class_release(struct kobject *kobj)
 
 static const struct kobj_ns_type_operations *class_child_ns_type(const struct kobject *kobj)
 {
-       struct subsys_private *cp = to_subsys_private(kobj);
+       const struct subsys_private *cp = to_subsys_private(kobj);
        struct class *class = cp->class;
 
        return class->ns_type;
--

2.39.0

author maintainer
#2 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 6 lines · Greg Kroah-Hartman

The macro to_subsys_private() needs to switch to using container_of_const() as it turned out to being incorrectly casting a const pointer to a non-const one. Make this change and fix up the one offending user to be correctly handling a const pointer properly.

Quoted 4 lines
Quoted 2 lines
Cc "Rafael J. Wysocki" <[email protected]>

Thanks for the review!