Re: [PATCH] trace/osnoise: Do not use 'main' as variable name

From: Randy Dunlap
Date: Wed Sep 08 2021 - 12:09:28 EST


On 9/8/21 8:53 AM, Steven Rostedt wrote:
On Wed, 8 Sep 2021 08:14:07 -0700
Guenter Roeck <linux@xxxxxxxxxxxx> wrote:

gcc 11.x may get a hiccup when encountering 'main' as variable name.

kernel/trace/trace_osnoise.c: In function 'start_kthread':
kernel/trace/trace_osnoise.c:1515:8: error: 'main' is usually a function

Use a different variable name to silence it.

Egad, no. NACK! Double NACK. Linus already NACK'd this.

(although it's ironic that he also added -Werror as the default :-/ )

The bug in is in gcc, go send them a patch.

THERE IS NO ISSUE WITH HAVING A LOCAL VARIABLE NAMED "main"!!!!

This has already been discussed:

https://lore.kernel.org/all/CAHk-=whHxeUjaNrWOLb0qx=-nibRZzQomwkw9xMPH_aHCf=BWQ@xxxxxxxxxxxxxx/

For now, the workaround is this patch:

https://lore.kernel.org/all/20210813224131.25803-1-rdunlap@xxxxxxxxxxxxx/


-- Steve



Signed-off-by: Guenter Roeck <linux@xxxxxxxxxxxx>
---
kernel/trace/trace_osnoise.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index 65b08b8e5bf8..7a4c73b4fdcf 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -1512,20 +1512,20 @@ static void stop_per_cpu_kthreads(void)
static int start_kthread(unsigned int cpu)
{
struct task_struct *kthread;
- void *main = osnoise_main;
+ void *func = osnoise_main;
char comm[24];
#ifdef CONFIG_TIMERLAT_TRACER
if (osnoise_data.timerlat_tracer) {
snprintf(comm, 24, "timerlat/%d", cpu);
- main = timerlat_main;
+ func = timerlat_main;
} else {
snprintf(comm, 24, "osnoise/%d", cpu);
}
#else
snprintf(comm, 24, "osnoise/%d", cpu);
#endif
- kthread = kthread_create_on_cpu(main, NULL, cpu, comm);
+ kthread = kthread_create_on_cpu(func, NULL, cpu, comm);
if (IS_ERR(kthread)) {
pr_err(BANNER "could not start sampling thread\n");


Preferably Linus's version:

https://lore.kernel.org/all/73ee98a4-c4a5-04f3-6280-dcd67507d889@xxxxxxxxxxxxx/


--
~Randy