Skip to content

Commit 49968cf

Browse files
committed
debugobjects: Reuse put_objects() on OOM
Reuse the helper function instead of having a open coded copy. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Zhen Lei <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent a2a7023 commit 49968cf

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

lib/debugobjects.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ static void free_object(struct debug_obj *obj)
429429
}
430430
}
431431

432-
#ifdef CONFIG_HOTPLUG_CPU
433432
static void put_objects(struct hlist_head *list)
434433
{
435434
struct hlist_node *tmp;
@@ -445,6 +444,7 @@ static void put_objects(struct hlist_head *list)
445444
}
446445
}
447446

447+
#ifdef CONFIG_HOTPLUG_CPU
448448
static int object_cpu_offline(unsigned int cpu)
449449
{
450450
/* Remote access is safe as the CPU is dead already */
@@ -456,31 +456,19 @@ static int object_cpu_offline(unsigned int cpu)
456456
}
457457
#endif
458458

459-
/*
460-
* We run out of memory. That means we probably have tons of objects
461-
* allocated.
462-
*/
459+
/* Out of memory. Free all objects from hash */
463460
static void debug_objects_oom(void)
464461
{
465462
struct debug_bucket *db = obj_hash;
466-
struct hlist_node *tmp;
467463
HLIST_HEAD(freelist);
468-
struct debug_obj *obj;
469-
unsigned long flags;
470-
int i;
471464

472465
pr_warn("Out of memory. ODEBUG disabled\n");
473466

474-
for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) {
475-
raw_spin_lock_irqsave(&db->lock, flags);
476-
hlist_move_list(&db->list, &freelist);
477-
raw_spin_unlock_irqrestore(&db->lock, flags);
467+
for (int i = 0; i < ODEBUG_HASH_SIZE; i++, db++) {
468+
scoped_guard(raw_spinlock_irqsave, &db->lock)
469+
hlist_move_list(&db->list, &freelist);
478470

479-
/* Now free them */
480-
hlist_for_each_entry_safe(obj, tmp, &freelist, node) {
481-
hlist_del(&obj->node);
482-
free_object(obj);
483-
}
471+
put_objects(&freelist);
484472
}
485473
}
486474

0 commit comments

Comments
 (0)