Skip to content

Commit 89c86a6

Browse files
bjorn-helgaasgregkh
authored andcommitted
kobject: delay kobject release for random time
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 <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2322392 commit 89c86a6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/kobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/export.h>
1919
#include <linux/stat.h>
2020
#include <linux/slab.h>
21+
#include <linux/random.h>
2122

2223
/**
2324
* kobject_namespace - return @kobj's namespace tag
@@ -642,10 +643,12 @@ static void kobject_release(struct kref *kref)
642643
{
643644
struct kobject *kobj = container_of(kref, struct kobject, kref);
644645
#ifdef CONFIG_DEBUG_KOBJECT_RELEASE
645-
pr_info("kobject: '%s' (%p): %s, parent %p (delayed)\n",
646-
kobject_name(kobj), kobj, __func__, kobj->parent);
646+
unsigned long delay = HZ + HZ * (get_random_int() & 0x3);
647+
pr_info("kobject: '%s' (%p): %s, parent %p (delayed %ld)\n",
648+
kobject_name(kobj), kobj, __func__, kobj->parent, delay);
647649
INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup);
648-
schedule_delayed_work(&kobj->release, HZ);
650+
651+
schedule_delayed_work(&kobj->release, delay);
649652
#else
650653
kobject_cleanup(kobj);
651654
#endif

0 commit comments

Comments
 (0)