kobject: delay kobject release for random time
authorBjorn Helgaas <bhelgaas@google.com>
Fri, 6 Dec 2013 00:37:51 +0000 (17:37 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 8 Dec 2013 05:14:13 +0000 (21:14 -0800)
When CONFIG_DEBUG_KOBJECT_RELEASE=y, delay kobject release functions for a
random time between 1 and 8 seconds, which effectively changes the order in
which they're called.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/kobject.c

index b8d848fb13772b93c5731115e8e776712c4fb593..1d110dc95db544e8757d610faf3f5bbad7f9af20 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/export.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
+#include <linux/random.h>
 
 /**
  * kobject_namespace - return @kobj's namespace tag
@@ -642,10 +643,12 @@ static void kobject_release(struct kref *kref)
 {
        struct kobject *kobj = container_of(kref, struct kobject, kref);
 #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
-       pr_info("kobject: '%s' (%p): %s, parent %p (delayed)\n",
-                kobject_name(kobj), kobj, __func__, kobj->parent);
+       unsigned long delay = HZ + HZ * (get_random_int() & 0x3);
+       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);
-       schedule_delayed_work(&kobj->release, HZ);
+
+       schedule_delayed_work(&kobj->release, delay);
 #else
        kobject_cleanup(kobj);
 #endif