2019-06-14 18:16:37

by Nathan Huckleberry

[permalink] [raw]
Subject: [PATCH] timer_list: Fix Wunused-const-variable

Clang produced the following warning when using allnoconfig

kernel/time/timer_list.c:361:36: warning: unused variable
'timer_list_sops' [-Wunused-const-variable]
static const struct seq_operations timer_list_sops = {

Code reliant on CONFIG_PROC_FS is not in ifdef guard.
Created ifdef guard around proc_fs specific code.

Cc: [email protected]
Link: https://github.com/ClangBuiltLinux/linux/issues/534
Signed-off-by: Nathan Huckleberry <[email protected]>
---
kernel/time/timer_list.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 98ba50dcb1b2..acb326f5f50a 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -282,23 +282,6 @@ static inline void timer_list_header(struct seq_file *m, u64 now)
SEQ_printf(m, "\n");
}

-static int timer_list_show(struct seq_file *m, void *v)
-{
- struct timer_list_iter *iter = v;
-
- if (iter->cpu == -1 && !iter->second_pass)
- timer_list_header(m, iter->now);
- else if (!iter->second_pass)
- print_cpu(m, iter->cpu, iter->now);
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
- else if (iter->cpu == -1 && iter->second_pass)
- timer_list_show_tickdevices_header(m);
- else
- print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
-#endif
- return 0;
-}
-
void sysrq_timer_list_show(void)
{
u64 now = ktime_to_ns(ktime_get());
@@ -317,6 +300,24 @@ void sysrq_timer_list_show(void)
return;
}

+#ifdef CONFIG_PROC_FS
+static int timer_list_show(struct seq_file *m, void *v)
+{
+ struct timer_list_iter *iter = v;
+
+ if (iter->cpu == -1 && !iter->second_pass)
+ timer_list_header(m, iter->now);
+ else if (!iter->second_pass)
+ print_cpu(m, iter->cpu, iter->now);
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
+ else if (iter->cpu == -1 && iter->second_pass)
+ timer_list_show_tickdevices_header(m);
+ else
+ print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
+#endif
+ return 0;
+}
+
static void *move_iter(struct timer_list_iter *iter, loff_t offset)
{
for (; offset; offset--) {
@@ -376,3 +377,4 @@ static int __init init_timer_list_procfs(void)
return 0;
}
__initcall(init_timer_list_procfs);
+#endif
--
2.22.0.410.gd8fdbe21b5-goog


2019-06-14 21:26:30

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] timer_list: Fix Wunused-const-variable

On Fri, Jun 14, 2019 at 11:16 AM 'Nathan Huckleberry' via Clang Built
Linux <[email protected]> wrote:
>
> Clang produced the following warning when using allnoconfig
>
> kernel/time/timer_list.c:361:36: warning: unused variable
> 'timer_list_sops' [-Wunused-const-variable]
> static const struct seq_operations timer_list_sops = {
>
> Code reliant on CONFIG_PROC_FS is not in ifdef guard.
> Created ifdef guard around proc_fs specific code.

Specifically, it sounds like proc_create_seq_private expands to an
empty GNU C statement expression (not sure why not a `static inline`
function returning `NULL` but ok), so in that case, this object full
of function pointer, and its pointed to static functions (whose sole
references are this object) all become dead code.

>
> Cc: [email protected]
> Link: https://github.com/ClangBuiltLinux/linux/issues/534
> Signed-off-by: Nathan Huckleberry <[email protected]>

Thanks for the patch, looks good! Make sure to include reported by
tags when someone else has reported an issue that you fix, in this
case:

Reported-by: kbuild test robot <[email protected]>
Link: https://groups.google.com/forum/#!topic/clang-built-linux/w27FQOTlb70
Reviewed-by: Nick Desaulniers <[email protected]>

> ---
> kernel/time/timer_list.c | 36 +++++++++++++++++++-----------------
> 1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
> index 98ba50dcb1b2..acb326f5f50a 100644
> --- a/kernel/time/timer_list.c
> +++ b/kernel/time/timer_list.c
> @@ -282,23 +282,6 @@ static inline void timer_list_header(struct seq_file *m, u64 now)
> SEQ_printf(m, "\n");
> }
>
> -static int timer_list_show(struct seq_file *m, void *v)
> -{
> - struct timer_list_iter *iter = v;
> -
> - if (iter->cpu == -1 && !iter->second_pass)
> - timer_list_header(m, iter->now);
> - else if (!iter->second_pass)
> - print_cpu(m, iter->cpu, iter->now);
> -#ifdef CONFIG_GENERIC_CLOCKEVENTS
> - else if (iter->cpu == -1 && iter->second_pass)
> - timer_list_show_tickdevices_header(m);
> - else
> - print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
> -#endif
> - return 0;
> -}
> -
> void sysrq_timer_list_show(void)
> {
> u64 now = ktime_to_ns(ktime_get());
> @@ -317,6 +300,24 @@ void sysrq_timer_list_show(void)
> return;
> }
>
> +#ifdef CONFIG_PROC_FS
> +static int timer_list_show(struct seq_file *m, void *v)
> +{
> + struct timer_list_iter *iter = v;
> +
> + if (iter->cpu == -1 && !iter->second_pass)
> + timer_list_header(m, iter->now);
> + else if (!iter->second_pass)
> + print_cpu(m, iter->cpu, iter->now);
> +#ifdef CONFIG_GENERIC_CLOCKEVENTS
> + else if (iter->cpu == -1 && iter->second_pass)
> + timer_list_show_tickdevices_header(m);
> + else
> + print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
> +#endif
> + return 0;
> +}
> +
> static void *move_iter(struct timer_list_iter *iter, loff_t offset)
> {
> for (; offset; offset--) {
> @@ -376,3 +377,4 @@ static int __init init_timer_list_procfs(void)
> return 0;
> }
> __initcall(init_timer_list_procfs);
> +#endif
> --
> 2.22.0.410.gd8fdbe21b5-goog
>
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20190614181604.112297-1-nhuck%40google.com.
> For more options, visit https://groups.google.com/d/optout.



--
Thanks,
~Nick Desaulniers

Subject: [tip:timers/core] timer_list: Guard procfs specific code

Commit-ID: a9314773a91a1d3b36270085246a6715a326ff00
Gitweb: https://git.kernel.org/tip/a9314773a91a1d3b36270085246a6715a326ff00
Author: Nathan Huckleberry <[email protected]>
AuthorDate: Fri, 14 Jun 2019 11:16:04 -0700
Committer: Thomas Gleixner <[email protected]>
CommitDate: Sun, 23 Jun 2019 00:08:52 +0200

timer_list: Guard procfs specific code

With CONFIG_PROC_FS=n the following warning is emitted:

kernel/time/timer_list.c:361:36: warning: unused variable
'timer_list_sops' [-Wunused-const-variable]
static const struct seq_operations timer_list_sops = {

Add #ifdef guard around procfs specific code.

Signed-off-by: Nathan Huckleberry <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Nick Desaulniers <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://github.com/ClangBuiltLinux/linux/issues/534
Link: https://lkml.kernel.org/r/[email protected]

---
kernel/time/timer_list.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
index 98ba50dcb1b2..acb326f5f50a 100644
--- a/kernel/time/timer_list.c
+++ b/kernel/time/timer_list.c
@@ -282,23 +282,6 @@ static inline void timer_list_header(struct seq_file *m, u64 now)
SEQ_printf(m, "\n");
}

-static int timer_list_show(struct seq_file *m, void *v)
-{
- struct timer_list_iter *iter = v;
-
- if (iter->cpu == -1 && !iter->second_pass)
- timer_list_header(m, iter->now);
- else if (!iter->second_pass)
- print_cpu(m, iter->cpu, iter->now);
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
- else if (iter->cpu == -1 && iter->second_pass)
- timer_list_show_tickdevices_header(m);
- else
- print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
-#endif
- return 0;
-}
-
void sysrq_timer_list_show(void)
{
u64 now = ktime_to_ns(ktime_get());
@@ -317,6 +300,24 @@ void sysrq_timer_list_show(void)
return;
}

+#ifdef CONFIG_PROC_FS
+static int timer_list_show(struct seq_file *m, void *v)
+{
+ struct timer_list_iter *iter = v;
+
+ if (iter->cpu == -1 && !iter->second_pass)
+ timer_list_header(m, iter->now);
+ else if (!iter->second_pass)
+ print_cpu(m, iter->cpu, iter->now);
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
+ else if (iter->cpu == -1 && iter->second_pass)
+ timer_list_show_tickdevices_header(m);
+ else
+ print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
+#endif
+ return 0;
+}
+
static void *move_iter(struct timer_list_iter *iter, loff_t offset)
{
for (; offset; offset--) {
@@ -376,3 +377,4 @@ static int __init init_timer_list_procfs(void)
return 0;
}
__initcall(init_timer_list_procfs);
+#endif