maple_tree: add RCU lock checking to rcu callback functions
[platform/kernel/linux-starfive.git] / lib / kobject.c
index 5f0e71a..aa375a5 100644 (file)
@@ -94,10 +94,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.
@@ -112,21 +112,25 @@ static int get_kobj_path_length(struct kobject *kobj)
        return length;
 }
 
-static void fill_kobj_path(struct kobject *kobj, char *path, int length)
+static int 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) {
                int cur = strlen(kobject_name(parent));
                /* back up enough to print this name with '/' */
                length -= cur;
+               if (length <= 0)
+                       return -EINVAL;
                memcpy(path + length, kobject_name(parent), cur);
                *(path + --length) = '/';
        }
 
        pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
                 kobj, __func__, path);
+
+       return 0;
 }
 
 /**
@@ -136,18 +140,22 @@ 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;
 
+retry:
        len = get_kobj_path_length(kobj);
        if (len == 0)
                return NULL;
        path = kzalloc(len, gfp_mask);
        if (!path)
                return NULL;
-       fill_kobj_path(kobj, path, len);
+       if (fill_kobj_path(kobj, path, len)) {
+               kfree(path);
+               goto retry;
+       }
 
        return path;
 }
@@ -694,7 +702,7 @@ static void kobject_release(struct kref *kref)
 {
        struct kobject *kobj = container_of(kref, struct kobject, kref);
 #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
-       unsigned long delay = HZ + HZ * (get_random_int() & 0x3);
+       unsigned long delay = HZ + HZ * prandom_u32_max(4);
        pr_info("kobject: '%s' (%p): %s, parent %p (delayed %ld)\n",
                 kobject_name(kobj), kobj, __func__, kobj->parent, delay);
        INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup);