Skip to content

Commit

Permalink
kobject: make kobject_get_ownership() take a constant kobject *
Browse files Browse the repository at this point in the history
The call, kobject_get_ownership(), does not modify the kobject passed
into it, so make it const.  This propagates down into the kobj_type
function callbacks so make the kobject passed into them also const,
ensuring that nothing in the kobject is being changed here.

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

Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Anna Schumaker <anna@kernel.org>
Cc: Roopa Prabhu <roopa@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org
Cc: bridge@lists.linux-foundation.org
Cc: netdev@vger.kernel.org
Acked-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Link: https://lore.kernel.org/r/20221121094649.1556002-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
gregkh committed Nov 22, 2022
1 parent 05df6ab commit 02a476d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion drivers/base/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static void class_release(struct kobject *kobj)
kfree(cp);
}

static const struct kobj_ns_type_operations *class_child_ns_type(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);
struct class *class = cp->class;
Expand Down
8 changes: 4 additions & 4 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@ static void device_release(struct kobject *kobj)
kfree(p);
}

static const void *device_namespace(struct kobject *kobj)
static const void *device_namespace(const struct kobject *kobj)
{
const struct device *dev = kobj_to_dev(kobj);
const void *ns = NULL;
Expand All @@ -2346,7 +2346,7 @@ static const void *device_namespace(struct kobject *kobj)
return ns;
}

static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
static void device_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid)
{
const struct device *dev = kobj_to_dev(kobj);

Expand Down Expand Up @@ -2986,9 +2986,9 @@ static void class_dir_release(struct kobject *kobj)
}

static const
struct kobj_ns_type_operations *class_dir_child_ns_type(struct kobject *kobj)
struct kobj_ns_type_operations *class_dir_child_ns_type(const struct kobject *kobj)
{
struct class_dir *dir = to_class_dir(kobj);
const struct class_dir *dir = to_class_dir(kobj);
return dir->class->ns_type;
}

Expand Down
4 changes: 2 additions & 2 deletions fs/nfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void nfs_netns_object_release(struct kobject *kobj)
}

static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
struct kobject *kobj)
const struct kobject *kobj)
{
return &net_ns_type_operations;
}
Expand Down Expand Up @@ -130,7 +130,7 @@ static void nfs_netns_client_release(struct kobject *kobj)
kfree(c);
}

static const void *nfs_netns_client_namespace(struct kobject *kobj)
static const void *nfs_netns_client_namespace(const struct kobject *kobj)
{
return container_of(kobj, struct nfs_netns_client, kobject)->net;
}
Expand Down
8 changes: 4 additions & 4 deletions include/linux/kobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ extern struct kobject * __must_check kobject_get_unless_zero(
extern void kobject_put(struct kobject *kobj);

extern const void *kobject_namespace(struct kobject *kobj);
extern void kobject_get_ownership(struct kobject *kobj,
extern void kobject_get_ownership(const struct kobject *kobj,
kuid_t *uid, kgid_t *gid);
extern 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 kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
const void *(*namespace)(struct kobject *kobj);
void (*get_ownership)(struct kobject *kobj, kuid_t *uid, kgid_t *gid);
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);
};

struct kobj_uevent_env {
Expand Down
4 changes: 2 additions & 2 deletions lib/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const void *kobject_namespace(struct kobject *kobj)
* representation of given kobject. Normally used to adjust ownership of
* objects in a container.
*/
void kobject_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
void kobject_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid)
{
*uid = GLOBAL_ROOT_UID;
*gid = GLOBAL_ROOT_GID;
Expand Down Expand Up @@ -907,7 +907,7 @@ static void kset_release(struct kobject *kobj)
kfree(kset);
}

static void kset_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
static void kset_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid)
{
if (kobj->parent)
kobject_get_ownership(kobj->parent, uid, gid);
Expand Down
2 changes: 1 addition & 1 deletion net/bridge/br_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static void release_nbp(struct kobject *kobj)
kfree(p);
}

static void brport_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
static void brport_get_ownership(const struct kobject *kobj, kuid_t *uid, kgid_t *gid)
{
struct net_bridge_port *p = kobj_to_brport(kobj);

Expand Down
8 changes: 4 additions & 4 deletions net/core/net-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ static void rx_queue_release(struct kobject *kobj)
netdev_put(queue->dev, &queue->dev_tracker);
}

static const void *rx_queue_namespace(struct kobject *kobj)
static const void *rx_queue_namespace(const struct kobject *kobj)
{
struct netdev_rx_queue *queue = to_rx_queue(kobj);
struct device *dev = &queue->dev->dev;
Expand All @@ -1032,7 +1032,7 @@ static const void *rx_queue_namespace(struct kobject *kobj)
return ns;
}

static void rx_queue_get_ownership(struct kobject *kobj,
static void rx_queue_get_ownership(const struct kobject *kobj,
kuid_t *uid, kgid_t *gid)
{
const struct net *net = rx_queue_namespace(kobj);
Expand Down Expand Up @@ -1623,7 +1623,7 @@ static void netdev_queue_release(struct kobject *kobj)
netdev_put(queue->dev, &queue->dev_tracker);
}

static const void *netdev_queue_namespace(struct kobject *kobj)
static const void *netdev_queue_namespace(const struct kobject *kobj)
{
struct netdev_queue *queue = to_netdev_queue(kobj);
struct device *dev = &queue->dev->dev;
Expand All @@ -1635,7 +1635,7 @@ static const void *netdev_queue_namespace(struct kobject *kobj)
return ns;
}

static void netdev_queue_get_ownership(struct kobject *kobj,
static void netdev_queue_get_ownership(const struct kobject *kobj,
kuid_t *uid, kgid_t *gid)
{
const struct net *net = netdev_queue_namespace(kobj);
Expand Down
8 changes: 4 additions & 4 deletions net/sunrpc/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void rpc_sysfs_object_release(struct kobject *kobj)
}

static const struct kobj_ns_type_operations *
rpc_sysfs_object_child_ns_type(struct kobject *kobj)
rpc_sysfs_object_child_ns_type(const struct kobject *kobj)
{
return &net_ns_type_operations;
}
Expand Down Expand Up @@ -381,17 +381,17 @@ static void rpc_sysfs_xprt_release(struct kobject *kobj)
kfree(xprt);
}

static const void *rpc_sysfs_client_namespace(struct kobject *kobj)
static const void *rpc_sysfs_client_namespace(const struct kobject *kobj)
{
return container_of(kobj, struct rpc_sysfs_client, kobject)->net;
}

static const void *rpc_sysfs_xprt_switch_namespace(struct kobject *kobj)
static const void *rpc_sysfs_xprt_switch_namespace(const struct kobject *kobj)
{
return container_of(kobj, struct rpc_sysfs_xprt_switch, kobject)->net;
}

static const void *rpc_sysfs_xprt_namespace(struct kobject *kobj)
static const void *rpc_sysfs_xprt_namespace(const struct kobject *kobj)
{
return container_of(kobj, struct rpc_sysfs_xprt,
kobject)->xprt->xprt_net;
Expand Down

0 comments on commit 02a476d

Please sign in to comment.