Re: [PATCH] sched/topology: remove unneeded do while loop in cpu_attach_domain()

From: Peter Zijlstra
Date: Tue Jun 20 2023 - 10:12:19 EST


On Sat, Jun 17, 2023 at 04:19:26PM +0800, Miaohe Lin wrote:
> When sg != sd->groups, the do while loop would cause deadloop here. But
> that won't occur because sg is always equal to sd->groups now. Remove
> this unneeded do while loop.

This Changelog makes no sense to me.. Yes, as is the do {} while loop is
dead code, but it *should* have read like:

do {
sg->flags = 0;
sg = sg->next;
} while (sg != sd->groups);

as I noted here:

https://lore.kernel.org/all/20230523105935.GN83892@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/T/#u

So what this changelog should argue is how there cannot be multiple
groups here -- or if there can be, add the missing iteration.

> Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>
> ---
> kernel/sched/topology.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index ca4472281c28..9010c93c3fdb 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -750,10 +750,7 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
> * domain for convenience. Clear such flags since
> * the child is being destroyed.
> */
> - do {
> - sg->flags = 0;
> - } while (sg != sd->groups);
> -
> + sg->flags = 0;
> sd->child = NULL;
> }
> }
> --
> 2.27.0
>