kobject: modify kobject_get_path() to take a const *
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 1 Oct 2022 16:53:15 +0000 (18:53 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Mar 2023 08:39:35 +0000 (09:39 +0100)
[ Upstream commit 33a0a1e3b3d17445832177981dc7a1c6a5b009f8 ]

kobject_get_path() does not modify the kobject passed to it, so make the
pointer constant.

Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Link: https://lore.kernel.org/r/20221001165315.2690141-1-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Stable-dep-of: 3bb2a01caa81 ("kobject: Fix slab-out-of-bounds in fill_kobj_path()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/kobject.h
lib/kobject.c

index ea30529fba08ac94131e30d54f3565c0a61ff17c..d38916e598a59968bd16aa767d45781a6626c1f4 100644 (file)
@@ -116,7 +116,7 @@ extern void kobject_put(struct kobject *kobj);
 extern const void *kobject_namespace(struct kobject *kobj);
 extern void kobject_get_ownership(struct kobject *kobj,
                                  kuid_t *uid, kgid_t *gid);
-extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
+extern char *kobject_get_path(const struct kobject *kobj, gfp_t flag);
 
 /**
  * kobject_has_children - Returns whether a kobject has children.
index ea53b30cf4837969326dac3282e1fd364edbd3a9..94ff7fd5d80bc9dd24e85ce9946fd4b4b987d57e 100644 (file)
@@ -126,10 +126,10 @@ static int create_dir(struct kobject *kobj)
        return 0;
 }
 
-static int get_kobj_path_length(struct kobject *kobj)
+static int get_kobj_path_length(const struct kobject *kobj)
 {
        int length = 1;
-       struct kobject *parent = kobj;
+       const struct kobject *parent = kobj;
 
        /* walk up the ancestors until we hit the one pointing to the
         * root.
@@ -144,9 +144,9 @@ static int get_kobj_path_length(struct kobject *kobj)
        return length;
 }
 
-static void fill_kobj_path(struct kobject *kobj, char *path, int length)
+static void fill_kobj_path(const struct kobject *kobj, char *path, int length)
 {
-       struct kobject *parent;
+       const struct kobject *parent;
 
        --length;
        for (parent = kobj; parent; parent = parent->parent) {
@@ -168,7 +168,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
  *
  * Return: The newly allocated memory, caller must free with kfree().
  */
-char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
+char *kobject_get_path(const struct kobject *kobj, gfp_t gfp_mask)
 {
        char *path;
        int len;