Re: [PATCH] kernel/sched/core.c: Avoid unused variable on non-SMP configs

From: Miguel Ojeda
Date: Sun Sep 09 2018 - 10:48:52 EST


On Sun, Sep 9, 2018 at 11:36 AM, Borislav Petkov <bp@xxxxxxxxx> wrote:
>
> Alternatively, if you don't want to let the crazy ifdeffery in that
> function grow even more, you can simply do:
>
> ---
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 625bc9897f62..1728743360d4 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -136,7 +136,7 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
> * to sched_rt_avg_update. But I don't trust it...
> */
> #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING)
> - s64 steal = 0, irq_delta = 0;
> + s64 steal __maybe_unused = 0, irq_delta = 0;
> #endif

Indeed. But note that the attribute needs to be written before the
variable name so that it applies to both variables (or write it twice)
--- see https://godbolt.org/z/cwOeXZ

Also, if we go that route, I would simply remove the #ifdef entirely.

Cheers,
Miguel