Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

timers/migration: Convert "while" loops to use "for"

Both the "do while" and "while" loops in tmigr_setup_groups() eventually
mimic the behaviour of "for" loops.

Simplify accordingly.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://patch.msgid.link/20251024132536.39841-2-frederic@kernel.org

authored by

Frederic Weisbecker and committed by
Thomas Gleixner
6c181b56 41387874

+13 -10
+13 -10
kernel/time/timer_migration.c
··· 1642 1642 static int tmigr_setup_groups(unsigned int cpu, unsigned int node) 1643 1643 { 1644 1644 struct tmigr_group *group, *child, **stack; 1645 - int top = 0, err = 0, i = 0; 1645 + int i, top = 0, err = 0; 1646 1646 struct list_head *lvllist; 1647 1647 1648 1648 stack = kcalloc(tmigr_hierarchy_levels, sizeof(*stack), GFP_KERNEL); 1649 1649 if (!stack) 1650 1650 return -ENOMEM; 1651 1651 1652 - do { 1652 + for (i = 0; i < tmigr_hierarchy_levels; i++) { 1653 1653 group = tmigr_get_group(cpu, node, i); 1654 1654 if (IS_ERR(group)) { 1655 1655 err = PTR_ERR(group); 1656 + i--; 1656 1657 break; 1657 1658 } 1658 1659 1659 1660 top = i; 1660 - stack[i++] = group; 1661 + stack[i] = group; 1661 1662 1662 1663 /* 1663 1664 * When booting only less CPUs of a system than CPUs are ··· 1668 1667 * be different from tmigr_hierarchy_levels, contains only a 1669 1668 * single group. 1670 1669 */ 1671 - if (group->parent || list_is_singular(&tmigr_level_list[i - 1])) 1670 + if (group->parent || list_is_singular(&tmigr_level_list[i])) 1672 1671 break; 1672 + } 1673 1673 1674 - } while (i < tmigr_hierarchy_levels); 1674 + /* Assert single root without parent */ 1675 + if (WARN_ON_ONCE(i >= tmigr_hierarchy_levels)) 1676 + return -EINVAL; 1677 + if (WARN_ON_ONCE(!err && !group->parent && !list_is_singular(&tmigr_level_list[top]))) 1678 + return -EINVAL; 1675 1679 1676 - /* Assert single root */ 1677 - WARN_ON_ONCE(!err && !group->parent && !list_is_singular(&tmigr_level_list[top])); 1678 - 1679 - while (i > 0) { 1680 - group = stack[--i]; 1680 + for (; i >= 0; i--) { 1681 + group = stack[i]; 1681 1682 1682 1683 if (err < 0) { 1683 1684 list_del(&group->list);