2024-04-18 10:51:28

by Dawei Li

[permalink] [raw]
Subject: [PATCH 2/5] sparc/irq: Remove on-stack cpumask var

In general it's preferable to avoid placing cpumasks on the stack, as
for large values of NR_CPUS these can consume significant amounts of
stack space and make stack overflows more likely.

- Both 2 arguments of cpumask_equal() is constant and free of change, no
need to allocate extra cpumask variables.

- Merge cpumask_and(), cpumask_first() and cpumask_empty() into
cpumask_first_and().

Signed-off-by: Dawei Li <[email protected]>
---
arch/sparc/kernel/irq_64.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/arch/sparc/kernel/irq_64.c b/arch/sparc/kernel/irq_64.c
index 5280e325d4d6..bc96f1bcd2fc 100644
--- a/arch/sparc/kernel/irq_64.c
+++ b/arch/sparc/kernel/irq_64.c
@@ -349,17 +349,13 @@ static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
#ifdef CONFIG_SMP
static int irq_choose_cpu(unsigned int irq, const struct cpumask *affinity)
{
- cpumask_t mask;
int cpuid;

- cpumask_copy(&mask, affinity);
- if (cpumask_equal(&mask, cpu_online_mask)) {
+ if (cpumask_equal(affinity, cpu_online_mask)) {
cpuid = map_to_cpu(irq);
} else {
- cpumask_t tmp;
-
- cpumask_and(&tmp, cpu_online_mask, &mask);
- cpuid = cpumask_empty(&tmp) ? map_to_cpu(irq) : cpumask_first(&tmp);
+ cpuid = cpumask_first_and(affinity, cpu_online_mask);
+ cpuid = cpuid < nr_cpu_ids ? : map_to_cpu(irq);
}

return cpuid;
--
2.27.0



2024-04-19 00:20:47

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 2/5] sparc/irq: Remove on-stack cpumask var

Hi Dawei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.9-rc4]
[also build test WARNING on linus/master next-20240418]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Dawei-Li/sparc-srmmu-Remove-on-stack-cpumask-var/20240418-185348
base: v6.9-rc4
patch link: https://lore.kernel.org/r/20240418104949.3606645-3-dawei.li%40shingroup.cn
patch subject: [PATCH 2/5] sparc/irq: Remove on-stack cpumask var
config: sparc64-defconfig (https://download.01.org/0day-ci/archive/20240419/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240419/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

arch/sparc/kernel/irq_64.c: In function 'irq_choose_cpu':
>> arch/sparc/kernel/irq_64.c:358:46: warning: the omitted middle operand in '?:' will always be 'true', suggest explicit middle operand [-Wparentheses]
358 | cpuid = cpuid < nr_cpu_ids ? : map_to_cpu(irq);
| ^


vim +358 arch/sparc/kernel/irq_64.c

348
349 #ifdef CONFIG_SMP
350 static int irq_choose_cpu(unsigned int irq, const struct cpumask *affinity)
351 {
352 int cpuid;
353
354 if (cpumask_equal(affinity, cpu_online_mask)) {
355 cpuid = map_to_cpu(irq);
356 } else {
357 cpuid = cpumask_first_and(affinity, cpu_online_mask);
> 358 cpuid = cpuid < nr_cpu_ids ? : map_to_cpu(irq);
359 }
360
361 return cpuid;
362 }
363 #else
364 #define irq_choose_cpu(irq, affinity) \
365 real_hard_smp_processor_id()
366 #endif
367

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki