All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver base: slience unused warning
@ 2023-08-31  7:36 Su Hui
  2023-08-31  7:50 ` Greg KH
  2023-09-07 10:49 ` Dan Carpenter
  0 siblings, 2 replies; 9+ messages in thread
From: Su Hui @ 2023-08-31  7:36 UTC (permalink / raw)
  To: gregkh, rafael; +Cc: linux-kernel, kernel-janitors, Su Hui

Avoid unused warning with gcc and W=1 option.

drivers/base/module.c:36:6: error:
variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/base/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/module.c b/drivers/base/module.c
index 46ad4d636731..10494336d601 100644
--- a/drivers/base/module.c
+++ b/drivers/base/module.c
@@ -33,7 +33,7 @@ static void module_create_drivers_dir(struct module_kobject *mk)
 void module_add_driver(struct module *mod, struct device_driver *drv)
 {
 	char *driver_name;
-	int no_warn;
+	int __maybe_unused no_warn;
 	struct module_kobject *mk = NULL;
 
 	if (!drv)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-08-31  7:36 [PATCH] driver base: slience unused warning Su Hui
@ 2023-08-31  7:50 ` Greg KH
  2023-09-07 10:49 ` Dan Carpenter
  1 sibling, 0 replies; 9+ messages in thread
From: Greg KH @ 2023-08-31  7:50 UTC (permalink / raw)
  To: Su Hui; +Cc: rafael, linux-kernel, kernel-janitors

On Thu, Aug 31, 2023 at 03:36:55PM +0800, Su Hui wrote:
> Avoid unused warning with gcc and W=1 option.
> 
> drivers/base/module.c:36:6: error:
> variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
> 
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
>  drivers/base/module.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/module.c b/drivers/base/module.c
> index 46ad4d636731..10494336d601 100644
> --- a/drivers/base/module.c
> +++ b/drivers/base/module.c
> @@ -33,7 +33,7 @@ static void module_create_drivers_dir(struct module_kobject *mk)
>  void module_add_driver(struct module *mod, struct device_driver *drv)
>  {
>  	char *driver_name;
> -	int no_warn;
> +	int __maybe_unused no_warn;

But no_warn is being used in this file, it's being set but not read
which is ok.  That's a real use, so this change really isn't correct,
sorry.

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-08-31  7:36 [PATCH] driver base: slience unused warning Su Hui
  2023-08-31  7:50 ` Greg KH
@ 2023-09-07 10:49 ` Dan Carpenter
  2023-09-08  1:23   ` Su Hui
  1 sibling, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2023-09-07 10:49 UTC (permalink / raw)
  To: Su Hui; +Cc: gregkh, rafael, linux-kernel, kernel-janitors

On Thu, Aug 31, 2023 at 03:36:55PM +0800, Su Hui wrote:
> Avoid unused warning with gcc and W=1 option.
> 
> drivers/base/module.c:36:6: error:
> variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
> 
> Signed-off-by: Su Hui <suhui@nfschina.com>
> ---
>  drivers/base/module.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/module.c b/drivers/base/module.c
> index 46ad4d636731..10494336d601 100644
> --- a/drivers/base/module.c
> +++ b/drivers/base/module.c
> @@ -33,7 +33,7 @@ static void module_create_drivers_dir(struct module_kobject *mk)
>  void module_add_driver(struct module *mod, struct device_driver *drv)
>  {
>  	char *driver_name;
> -	int no_warn;
> +	int __maybe_unused no_warn;

Just delete the variable if it isn't used.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-09-07 10:49 ` Dan Carpenter
@ 2023-09-08  1:23   ` Su Hui
  2023-10-04 15:02     ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Su Hui @ 2023-09-08  1:23 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: gregkh, rafael, linux-kernel, kernel-janitors


On 2023/9/7 18:49, Dan Carpenter wrote:
> On Thu, Aug 31, 2023 at 03:36:55PM +0800, Su Hui wrote:
>> Avoid unused warning with gcc and W=1 option.
>>
>> drivers/base/module.c:36:6: error:
>> variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
>>
>> Signed-off-by: Su Hui <suhui@nfschina.com>
>> ---
>>   drivers/base/module.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/module.c b/drivers/base/module.c
>> index 46ad4d636731..10494336d601 100644
>> --- a/drivers/base/module.c
>> +++ b/drivers/base/module.c
>> @@ -33,7 +33,7 @@ static void module_create_drivers_dir(struct module_kobject *mk)
>>   void module_add_driver(struct module *mod, struct device_driver *drv)
>>   {
>>   	char *driver_name;
>> -	int no_warn;
>> +	int __maybe_unused no_warn;
> Just delete the variable if it isn't used.

Hi,

The variable "no_warn" is used to avoid warning like this:

drivers/base/module.c: In function ‘module_add_driver’:
drivers/base/module.c:62:2: error: ignoring return value of 
‘sysfs_create_link’ declared with attribute ‘warn_unused_result’ 
[-Werror=unused-result]

    62 |  sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This variable is been used but never be read, so gcc and W=1 give such 
warning.

drivers/base/module.c:36:6: error:
variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]

I wanted to use "__maybe_unused" to avoid  this warning.

However it seems like a wrong using of "__maybe_unused" as Greg KH said:

"But no_warn is being used in this file, it's being set but not read
which is ok.  That's a real use, so this change really isn't correct,
sorry."

Su Hui

>   
>
> regards,
> dan carpenter
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-09-08  1:23   ` Su Hui
@ 2023-10-04 15:02     ` Maciej W. Rozycki
  2023-10-04 15:41       ` Dan Carpenter
  0 siblings, 1 reply; 9+ messages in thread
From: Maciej W. Rozycki @ 2023-10-04 15:02 UTC (permalink / raw)
  To: Su Hui
  Cc: Dan Carpenter, Greg Kroah-Hartman, rafael, linux-kernel, kernel-janitors

On Fri, 8 Sep 2023, Su Hui wrote:

> This variable is been used but never be read, so gcc and W=1 give such
> warning.
> 
> drivers/base/module.c:36:6: error:
> variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
> 
> I wanted to use "__maybe_unused" to avoid  this warning.
> 
> However it seems like a wrong using of "__maybe_unused" as Greg KH said:
> 
> "But no_warn is being used in this file, it's being set but not read
> which is ok.  That's a real use, so this change really isn't correct,
> sorry."

 The warning itself is a real issue to be sorted though.  Is this a use 
case for `#pragma GCC diagnostic'?

  Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-10-04 15:02     ` Maciej W. Rozycki
@ 2023-10-04 15:41       ` Dan Carpenter
  2023-10-05 12:24         ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2023-10-04 15:41 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Su Hui, Greg Kroah-Hartman, rafael, linux-kernel, kernel-janitors

On Wed, Oct 04, 2023 at 04:02:01PM +0100, Maciej W. Rozycki wrote:
> On Fri, 8 Sep 2023, Su Hui wrote:
> 
> > This variable is been used but never be read, so gcc and W=1 give such
> > warning.
> > 
> > drivers/base/module.c:36:6: error:
> > variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
> > 
> > I wanted to use "__maybe_unused" to avoid  this warning.
> > 
> > However it seems like a wrong using of "__maybe_unused" as Greg KH said:
> > 
> > "But no_warn is being used in this file, it's being set but not read
> > which is ok.  That's a real use, so this change really isn't correct,
> > sorry."
> 
>  The warning itself is a real issue to be sorted though.  Is this a use 
> case for `#pragma GCC diagnostic'?

I thought Greg liked using __maybe_unused in this case?  This is
drivers/base.  Do the rest of us even get a vote?  ;)

If I do have a vote then #pragma is always the worst option.  Linus has
taught me to dislike pragmas a lot.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-10-04 15:41       ` Dan Carpenter
@ 2023-10-05 12:24         ` Maciej W. Rozycki
  2023-10-05 13:44           ` Dan Carpenter
  0 siblings, 1 reply; 9+ messages in thread
From: Maciej W. Rozycki @ 2023-10-05 12:24 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Su Hui, Greg Kroah-Hartman, rafael, linux-kernel, kernel-janitors

On Wed, 4 Oct 2023, Dan Carpenter wrote:

> > > This variable is been used but never be read, so gcc and W=1 give such
> > > warning.
> > > 
> > > drivers/base/module.c:36:6: error:
> > > variable ‘no_warn’ set but not used [-Werror=unused-but-set-variable]
> > > 
> > > I wanted to use "__maybe_unused" to avoid  this warning.
> > > 
> > > However it seems like a wrong using of "__maybe_unused" as Greg KH said:
> > > 
> > > "But no_warn is being used in this file, it's being set but not read
> > > which is ok.  That's a real use, so this change really isn't correct,
> > > sorry."
> > 
> >  The warning itself is a real issue to be sorted though.  Is this a use 
> > case for `#pragma GCC diagnostic'?
> 
> I thought Greg liked using __maybe_unused in this case?  This is
> drivers/base.  Do the rest of us even get a vote?  ;)
> 
> If I do have a vote then #pragma is always the worst option.  Linus has
> taught me to dislike pragmas a lot.

 I'm not a great supporter of this solution, but at least it's guaranteed 
to work by definition.  Otherwise we could try to outsmart the compiler; 
perhaps:

	(no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj,
				     "module")), no_warn;

would work.  At the end of the day it's us who told the compiler to warn 
if the result of `sysfs_create_link' is unused with all the consequences.  
And while assigning to `no_warn' technically fulfils the requirement, the 
variable itself isn't used beyond being assigned to, which the compiler 
rightfully complains about because we asked for it.  It's up to us really 
to tell the compiler what we want it to complain about and what we do not.

  Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-10-05 12:24         ` Maciej W. Rozycki
@ 2023-10-05 13:44           ` Dan Carpenter
  2023-10-06 12:27             ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2023-10-05 13:44 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Su Hui, Greg Kroah-Hartman, rafael, linux-kernel, kernel-janitors

This is a W=1 static checker warning.  We've already reviewed it, and
marked it as old.  There isn't anything else required.

Or are we close to promoting the unused-but-set-variable warning from
W=1 to being on by default?  How many of these warnings are remaining?
It it's like only 20-50 warnings left then maybe we should consider the
other options but that kind of information needs to be in the cover
letter or otherwise we won't know about it.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] driver base: slience unused warning
  2023-10-05 13:44           ` Dan Carpenter
@ 2023-10-06 12:27             ` Maciej W. Rozycki
  0 siblings, 0 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2023-10-06 12:27 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Su Hui, Greg Kroah-Hartman, rafael, linux-kernel, kernel-janitors

On Thu, 5 Oct 2023, Dan Carpenter wrote:

> This is a W=1 static checker warning.  We've already reviewed it, and
> marked it as old.  There isn't anything else required.

 Good point.

> Or are we close to promoting the unused-but-set-variable warning from
> W=1 to being on by default?  How many of these warnings are remaining?
> It it's like only 20-50 warnings left then maybe we should consider the
> other options but that kind of information needs to be in the cover
> letter or otherwise we won't know about it.

 Hmm, these warnings do help chasing dead code, which in turn may reveal 
real issues, such as where someone missed or forgot something when writing 
their code and a value that was supposed to be used somehow is instead 
discarded.

 Most commonly it will be the case when some code has been deliberately 
removed as it evolves and a part that is no longer needed has been missed 
by chance and left in place.  I've seen it happen.  Apart from the code 
sloppiness resulting it shouldn't matter that much though as the compiler 
is usually pretty good at discarding dead code.

  Maciej

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-10-06 12:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31  7:36 [PATCH] driver base: slience unused warning Su Hui
2023-08-31  7:50 ` Greg KH
2023-09-07 10:49 ` Dan Carpenter
2023-09-08  1:23   ` Su Hui
2023-10-04 15:02     ` Maciej W. Rozycki
2023-10-04 15:41       ` Dan Carpenter
2023-10-05 12:24         ` Maciej W. Rozycki
2023-10-05 13:44           ` Dan Carpenter
2023-10-06 12:27             ` Maciej W. Rozycki

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.