* [PATCH v1] driver core: Silence 'unused-but-set variable' warning
@ 2022-12-23 14:51 Ammar Faizi
2022-12-23 15:02 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Ammar Faizi @ 2022-12-23 14:51 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Ammar Faizi, Rafael J. Wysocki, Linux Kernel Mailing List,
Nathan Chancellor, Nick Desaulniers, Tom Rix, LLVM Mailing List
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Compiling with clang-16:
drivers/base/module.c:36:6: error: variable 'no_warn' set but not \
used [-Werror,-Wunused-but-set-variable]
int no_warn;
^
1 error generated.
A reason the @no_warn variable exists is:
sysfs_create_link() return value needs not be ignored to silence
another warning.
So don't remove @no_warn, but add a '(void)no_warn;'.
Cc: LLVM Mailing List <llvm@lists.linux.dev>
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
drivers/base/module.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/base/module.c b/drivers/base/module.c
index 46ad4d636731..42f0b3b9e7f8 100644
--- a/drivers/base/module.c
+++ b/drivers/base/module.c
@@ -59,22 +59,23 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
return;
/* Don't check return codes; these calls are idempotent */
no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
driver_name = make_driver_name(drv);
if (driver_name) {
module_create_drivers_dir(mk);
no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj,
driver_name);
kfree(driver_name);
}
+ (void)no_warn;
}
void module_remove_driver(struct device_driver *drv)
{
struct module_kobject *mk = NULL;
char *driver_name;
if (!drv)
return;
sysfs_remove_link(&drv->p->kobj, "module");
base-commit: 8395ae05cb5a2e31d36106e8c85efa11cda849be
--
Ammar Faizi
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] driver core: Silence 'unused-but-set variable' warning
2022-12-23 14:51 [PATCH v1] driver core: Silence 'unused-but-set variable' warning Ammar Faizi
@ 2022-12-23 15:02 ` Greg Kroah-Hartman
2022-12-23 15:31 ` Ammar Faizi
0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2022-12-23 15:02 UTC (permalink / raw)
To: Ammar Faizi
Cc: Rafael J. Wysocki, Linux Kernel Mailing List, Nathan Chancellor,
Nick Desaulniers, Tom Rix, LLVM Mailing List
On Fri, Dec 23, 2022 at 09:51:37PM +0700, Ammar Faizi wrote:
> From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
>
> Compiling with clang-16:
>
> drivers/base/module.c:36:6: error: variable 'no_warn' set but not \
> used [-Werror,-Wunused-but-set-variable]
> int no_warn;
> ^
> 1 error generated.
>
> A reason the @no_warn variable exists is:
> sysfs_create_link() return value needs not be ignored to silence
> another warning.
>
> So don't remove @no_warn, but add a '(void)no_warn;'.
>
> Cc: LLVM Mailing List <llvm@lists.linux.dev>
> Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
> ---
> drivers/base/module.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/base/module.c b/drivers/base/module.c
> index 46ad4d636731..42f0b3b9e7f8 100644
> --- a/drivers/base/module.c
> +++ b/drivers/base/module.c
> @@ -59,22 +59,23 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
> return;
>
> /* Don't check return codes; these calls are idempotent */
> no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
> driver_name = make_driver_name(drv);
> if (driver_name) {
> module_create_drivers_dir(mk);
> no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj,
> driver_name);
> kfree(driver_name);
> }
> + (void)no_warn;
Ick, no, that's horrid and is NOT ok for kernel code, sorry.
Please fix the compiler, this is not a "fix" in any sense of the word
and is not going to work at all for kernel code.
sorry,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] driver core: Silence 'unused-but-set variable' warning
2022-12-23 15:02 ` Greg Kroah-Hartman
@ 2022-12-23 15:31 ` Ammar Faizi
2022-12-23 17:31 ` Nathan Chancellor
0 siblings, 1 reply; 4+ messages in thread
From: Ammar Faizi @ 2022-12-23 15:31 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Rafael J. Wysocki, Linux Kernel Mailing List, Nathan Chancellor,
Nick Desaulniers, Tom Rix, LLVM Mailing List
On 12/23/22 10:02 PM, Greg Kroah-Hartman wrote:
> Ick, no, that's horrid and is NOT ok for kernel code, sorry.
>
> Please fix the compiler, this is not a "fix" in any sense of the word
> and is not going to work at all for kernel code.
Agree.
Sorry for the noise. It turned out I messed up my clang compiler flags.
I forgot to do a "git reset --hard" before recompiling.
This has nothing todo with the upstream kernel.
--
Ammar Faizi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] driver core: Silence 'unused-but-set variable' warning
2022-12-23 15:31 ` Ammar Faizi
@ 2022-12-23 17:31 ` Nathan Chancellor
0 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2022-12-23 17:31 UTC (permalink / raw)
To: Ammar Faizi
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Linux Kernel Mailing List,
Nick Desaulniers, Tom Rix, LLVM Mailing List
On Fri, Dec 23, 2022 at 10:31:57PM +0700, Ammar Faizi wrote:
> On 12/23/22 10:02 PM, Greg Kroah-Hartman wrote:
> > Ick, no, that's horrid and is NOT ok for kernel code, sorry.
> >
> > Please fix the compiler, this is not a "fix" in any sense of the word
> > and is not going to work at all for kernel code.
It is possible that the compiler should not emit
-Wunused-but-set-variable when the variable is assigned the return
value of a function marked with __attribute__((warn_unused_result)) but
neither compiler does that today, you'll see the exact same warning from
GCC 12.2.0:
drivers/base/module.c: In function ‘module_add_driver’:
drivers/base/module.c:36:13: error: variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
36 | int no_warn;
| ^~~~~~~
cc1: all warnings being treated as errors
This has come up before too:
https://lore.kernel.org/20210726201924.3202278-2-morbo@google.com/
> Agree.
>
> Sorry for the noise. It turned out I messed up my clang compiler flags.
> I forgot to do a "git reset --hard" before recompiling.
>
> This has nothing todo with the upstream kernel.
This warning is in W=1, which are warnings that we want to turn on at
some point but the current instances need to be fixed first, so I would
say this is still relevant to the upstream kernel.
Cheers,
Nathan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-23 17:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-23 14:51 [PATCH v1] driver core: Silence 'unused-but-set variable' warning Ammar Faizi
2022-12-23 15:02 ` Greg Kroah-Hartman
2022-12-23 15:31 ` Ammar Faizi
2022-12-23 17:31 ` Nathan Chancellor
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.