Commit fa627348 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

driver core: class: make namespace and get_ownership take const *

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.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9a6800d1
...@@ -2336,7 +2336,7 @@ static void device_release(struct kobject *kobj) ...@@ -2336,7 +2336,7 @@ static void device_release(struct kobject *kobj)
static const void *device_namespace(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; const void *ns = NULL;
if (dev->class && dev->class->ns_type) if (dev->class && dev->class->ns_type)
...@@ -2347,7 +2347,7 @@ static const void *device_namespace(struct kobject *kobj) ...@@ -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) 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) if (dev->class && dev->class->get_ownership)
dev->class->get_ownership(dev, uid, gid); dev->class->get_ownership(dev, uid, gid);
......
...@@ -524,9 +524,9 @@ static int ib_device_uevent(struct device *device, ...@@ -524,9 +524,9 @@ static int ib_device_uevent(struct device *device,
return 0; 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); container_of(d, struct ib_core_device, dev);
return read_pnet(&coredev->rdma_net); return read_pnet(&coredev->rdma_net);
......
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
static dev_t ipvtap_major; static dev_t ipvtap_major;
static struct cdev ipvtap_cdev; 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); return dev_net(dev);
} }
......
...@@ -35,9 +35,9 @@ struct macvtap_dev { ...@@ -35,9 +35,9 @@ struct macvtap_dev {
*/ */
static dev_t macvtap_major; 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); return dev_net(dev);
} }
......
...@@ -68,9 +68,9 @@ struct class { ...@@ -68,9 +68,9 @@ struct class {
int (*shutdown_pre)(struct device *dev); int (*shutdown_pre)(struct device *dev);
const struct kobj_ns_type_operations *ns_type; 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; const struct dev_pm_ops *pm;
......
...@@ -1910,16 +1910,16 @@ static void netdev_release(struct device *d) ...@@ -1910,16 +1910,16 @@ static void netdev_release(struct device *d)
netdev_freemem(dev); 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); 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); const struct net *net = dev_net(dev);
net_ns_get_ownership(net, uid, gid); net_ns_get_ownership(net, uid, gid);
......
...@@ -148,7 +148,7 @@ static SIMPLE_DEV_PM_OPS(wiphy_pm_ops, wiphy_suspend, wiphy_resume); ...@@ -148,7 +148,7 @@ static SIMPLE_DEV_PM_OPS(wiphy_pm_ops, wiphy_suspend, wiphy_resume);
#define WIPHY_PM_OPS NULL #define WIPHY_PM_OPS NULL
#endif #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); struct wiphy *wiphy = container_of(d, struct wiphy, 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