driver core: class: make namespace and get_ownership take const *
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Oct 2022 16:54:26 +0000 (18:54 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Nov 2022 14:49:32 +0000 (15:49 +0100)
The callbacks in struct class namespace() and get_ownership() do not
modify the struct device passed to them, so mark the pointer as constant
and fix up all callbacks in the kernel to have the correct function
signature.

This helps make it more obvious what calls and callbacks do, and do not,
modify structures passed to them.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20221001165426.2690912-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c
drivers/infiniband/core/device.c
drivers/net/ipvlan/ipvtap.c
drivers/net/macvtap.c
include/linux/device/class.h
net/core/net-sysfs.c
net/wireless/sysfs.c

index d02501933467d443296e2dac60225ff8d3d2fbb6..f07b1c349f791c85232efca06cfb1333f71b73b9 100644 (file)
@@ -2336,7 +2336,7 @@ static void device_release(struct kobject *kobj)
 
 static const void *device_namespace(struct kobject *kobj)
 {
-       struct device *dev = kobj_to_dev(kobj);
+       const struct device *dev = kobj_to_dev(kobj);
        const void *ns = NULL;
 
        if (dev->class && dev->class->ns_type)
@@ -2347,7 +2347,7 @@ static const void *device_namespace(struct kobject *kobj)
 
 static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
 {
-       struct device *dev = kobj_to_dev(kobj);
+       const struct device *dev = kobj_to_dev(kobj);
 
        if (dev->class && dev->class->get_ownership)
                dev->class->get_ownership(dev, uid, gid);
index ae60c73babcc5a05ae0f3beedf38634eafc6f56c..3893b651742150ff13fe6ae3922ca0f79c75627f 100644 (file)
@@ -524,9 +524,9 @@ static int ib_device_uevent(struct device *device,
        return 0;
 }
 
-static const void *net_namespace(struct device *d)
+static const void *net_namespace(const struct device *d)
 {
-       struct ib_core_device *coredev =
+       const struct ib_core_device *coredev =
                        container_of(d, struct ib_core_device, dev);
 
        return read_pnet(&coredev->rdma_net);
index cbabca167a0785d136f59c11935f4c934cf8ad51..dde272586e80b5b2b7b0068a782af9cf6d96d8e0 100644 (file)
@@ -30,9 +30,9 @@
 static dev_t ipvtap_major;
 static struct cdev ipvtap_cdev;
 
-static const void *ipvtap_net_namespace(struct device *d)
+static const void *ipvtap_net_namespace(const struct device *d)
 {
-       struct net_device *dev = to_net_dev(d->parent);
+       const struct net_device *dev = to_net_dev(d->parent);
        return dev_net(dev);
 }
 
index d1f435788e9021277f4e904db5f240128d22c38b..031344239f27143506998685f2c01162d87b10f4 100644 (file)
@@ -35,9 +35,9 @@ struct macvtap_dev {
  */
 static dev_t macvtap_major;
 
-static const void *macvtap_net_namespace(struct device *d)
+static const void *macvtap_net_namespace(const struct device *d)
 {
-       struct net_device *dev = to_net_dev(d->parent);
+       const struct net_device *dev = to_net_dev(d->parent);
        return dev_net(dev);
 }
 
index e61ec55020197e361d246f63ac413a7e4b38a41c..20103e0b03c347df3a43d4caa35b95d87dfb43aa 100644 (file)
@@ -68,9 +68,9 @@ struct class {
        int (*shutdown_pre)(struct device *dev);
 
        const struct kobj_ns_type_operations *ns_type;
-       const void *(*namespace)(struct device *dev);
+       const void *(*namespace)(const struct device *dev);
 
-       void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
+       void (*get_ownership)(const struct device *dev, kuid_t *uid, kgid_t *gid);
 
        const struct dev_pm_ops *pm;
 
index 8409d41405dfe4a4448f3b7f070bdf9f856d74b8..a8c5a7cd9701d0df0b107865ab45cf98f099316d 100644 (file)
@@ -1910,16 +1910,16 @@ static void netdev_release(struct device *d)
        netdev_freemem(dev);
 }
 
-static const void *net_namespace(struct device *d)
+static const void *net_namespace(const struct device *d)
 {
-       struct net_device *dev = to_net_dev(d);
+       const struct net_device *dev = to_net_dev(d);
 
        return dev_net(dev);
 }
 
-static void net_get_ownership(struct device *d, kuid_t *uid, kgid_t *gid)
+static void net_get_ownership(const struct device *d, kuid_t *uid, kgid_t *gid)
 {
-       struct net_device *dev = to_net_dev(d);
+       const struct net_device *dev = to_net_dev(d);
        const struct net *net = dev_net(dev);
 
        net_ns_get_ownership(net, uid, gid);
index 0c3f05c9be27aca8c3d120a4c0bbbf3e05860396..cdb638647e0b655fbf27fee45c1a531593972408 100644 (file)
@@ -148,7 +148,7 @@ static SIMPLE_DEV_PM_OPS(wiphy_pm_ops, wiphy_suspend, wiphy_resume);
 #define WIPHY_PM_OPS NULL
 #endif
 
-static const void *wiphy_namespace(struct device *d)
+static const void *wiphy_namespace(const struct device *d)
 {
        struct wiphy *wiphy = container_of(d, struct wiphy, dev);