Commit 9fa120fb authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

driver core: device: mark struct class in struct device as constant

The pointer to a struct class in a struct device should never be used to
change anything in that class.  So mark it as constant to enforce this
requirement.

This requires a few minor changes to some internal driver core functions
to enforce the const * being used here now.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20230313181843.1207845-11-gregkh@linuxfoundation.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a010eb88
...@@ -2820,7 +2820,7 @@ EXPORT_SYMBOL_GPL(devm_device_add_groups); ...@@ -2820,7 +2820,7 @@ EXPORT_SYMBOL_GPL(devm_device_add_groups);
static int device_add_attrs(struct device *dev) static int device_add_attrs(struct device *dev)
{ {
struct class *class = dev->class; const struct class *class = dev->class;
const struct device_type *type = dev->type; const struct device_type *type = dev->type;
int error; int error;
...@@ -2887,7 +2887,7 @@ static int device_add_attrs(struct device *dev) ...@@ -2887,7 +2887,7 @@ static int device_add_attrs(struct device *dev)
static void device_remove_attrs(struct device *dev) static void device_remove_attrs(struct device *dev)
{ {
struct class *class = dev->class; const struct class *class = dev->class;
const struct device_type *type = dev->type; const struct device_type *type = dev->type;
if (dev->physical_location) { if (dev->physical_location) {
...@@ -3120,7 +3120,7 @@ struct kobject *virtual_device_parent(struct device *dev) ...@@ -3120,7 +3120,7 @@ struct kobject *virtual_device_parent(struct device *dev)
struct class_dir { struct class_dir {
struct kobject kobj; struct kobject kobj;
struct class *class; const struct class *class;
}; };
#define to_class_dir(obj) container_of(obj, struct class_dir, kobj) #define to_class_dir(obj) container_of(obj, struct class_dir, kobj)
...@@ -3145,7 +3145,7 @@ static const struct kobj_type class_dir_ktype = { ...@@ -3145,7 +3145,7 @@ static const struct kobj_type class_dir_ktype = {
}; };
static struct kobject * static struct kobject *
class_dir_create_and_add(struct class *class, struct kobject *parent_kobj) class_dir_create_and_add(const struct class *class, struct kobject *parent_kobj)
{ {
struct class_dir *dir; struct class_dir *dir;
int retval; int retval;
...@@ -4580,7 +4580,7 @@ static int device_attrs_change_owner(struct device *dev, kuid_t kuid, ...@@ -4580,7 +4580,7 @@ static int device_attrs_change_owner(struct device *dev, kuid_t kuid,
kgid_t kgid) kgid_t kgid)
{ {
struct kobject *kobj = &dev->kobj; struct kobject *kobj = &dev->kobj;
struct class *class = dev->class; const struct class *class = dev->class;
const struct device_type *type = dev->type; const struct device_type *type = dev->type;
int error; int error;
......
...@@ -631,7 +631,7 @@ struct device { ...@@ -631,7 +631,7 @@ struct device {
spinlock_t devres_lock; spinlock_t devres_lock;
struct list_head devres_head; struct list_head devres_head;
struct class *class; const struct class *class;
const struct attribute_group **groups; /* optional groups */ const struct attribute_group **groups; /* optional groups */
void (*release)(struct device *dev); void (*release)(struct device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment