Patchwork [1/3] wimax: fix '#ifdef CONFIG_BUG' layout to avoid warning

login
register
mail settings
Submitter Inaky Perez-Gonzalez
Date Jan. 7, 2009, 7:58 a.m.
Message ID <8baeb9679011f4f01a5f9709c725c4d829cb28bd.1231314782.git.inaky@linux.intel.com>
Download mbox | patch
Permalink /patch/17063/
State Superseded
Delegated to: David Miller
Headers show

Comments

Inaky Perez-Gonzalez - Jan. 7, 2009, 7:58 a.m.
Reported by Randy Dunlap:

> Also, this warning needs to be fixed:
>
> linux-next-20090106/net/wimax/id-table.c:133: warning: ISO C90
> forbids mixed declarations and code

Move the return on #defined(CONFIG_BUG) below the variable
declarations so it doesn't violate ISO C90.

On wimax_id_table_release() we want to do a debug check if CONFIG_BUG
is enabled. However, we also want the debug code to be always compiled
to ensure there is no bitrot. It will be optimized out by the compiler
when CONFIG_BUG is disabled.

Added a note to the function header stating this.

Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
---
 net/wimax/id-table.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
Ilpo Järvinen - Jan. 7, 2009, 10:25 a.m.
On Tue, 6 Jan 2009, Inaky Perez-Gonzalez wrote:

> Reported by Randy Dunlap:
> 
> > Also, this warning needs to be fixed:
> >
> > linux-next-20090106/net/wimax/id-table.c:133: warning: ISO C90
> > forbids mixed declarations and code
> 
> Move the return on #defined(CONFIG_BUG) below the variable
> declarations so it doesn't violate ISO C90.
> 
> On wimax_id_table_release() we want to do a debug check if CONFIG_BUG
> is enabled. However, we also want the debug code to be always compiled
> to ensure there is no bitrot.

I hope this kind of solution won't add some warnings? Besides, this seems 
rather strange reasoning as CONFIG_BUG is mostly enabled anyway?

> It will be optimized out by the compiler
> when CONFIG_BUG is disabled.
> 
> Added a note to the function header stating this.
> 
> Signed-off-by: Inaky Perez-Gonzalez <inaky@linux.intel.com>
> ---
>  net/wimax/id-table.c |   10 ++++++----
>  1 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/net/wimax/id-table.c b/net/wimax/id-table.c
> index d3b8855..d6e0e8f 100644
> --- a/net/wimax/id-table.c
> +++ b/net/wimax/id-table.c
> @@ -123,15 +123,17 @@ void wimax_id_table_rm(struct wimax_dev *wimax_dev)
>  /*
>   * Release the gennetlink family id / mapping table
>   *
> - * On debug, verify that the table is empty upon removal.
> + * On debug, verify that the table is empty upon removal. We want the
> + * code always compiled, to ensure it doesn't bit rot. It will be
> + * compiled out if CONFIG_BUG is disabled.
>   */
>  void wimax_id_table_release(void)
>  {
> -#ifndef CONFIG_BUG
> -	return;
> -#endif
>  	struct wimax_dev *wimax_dev;
>  
> +#ifdef CONFIG_BUG

Did you perhaps mean ifndef here??? :-)

> +	return;
> +#endif
>  	spin_lock(&wimax_id_table_lock);
>  	list_for_each_entry(wimax_dev, &wimax_id_table, id_table_node) {
>  		printk(KERN_ERR "BUG: %s wimax_dev %p ifindex %d not cleared\n",
>
Inaky Perez-Gonzalez - Jan. 7, 2009, 5:20 p.m.
On Wednesday 07 January 2009, Ilpo Järvinen wrote:
> On Tue, 6 Jan 2009, Inaky Perez-Gonzalez wrote:
> > Reported by Randy Dunlap:
> > > Also, this warning needs to be fixed:
> > >
> > > linux-next-20090106/net/wimax/id-table.c:133: warning: ISO C90
> > > forbids mixed declarations and code
> >
> > Move the return on #defined(CONFIG_BUG) below the variable
> > declarations so it doesn't violate ISO C90.
> >
> > On wimax_id_table_release() we want to do a debug check if CONFIG_BUG
> > is enabled. However, we also want the debug code to be always compiled
> > to ensure there is no bitrot.
>
> I hope this kind of solution won't add some warnings? Besides, this seems
> rather strange reasoning as CONFIG_BUG is mostly enabled anyway?

Well, it is legal code -- short of 'if (1) return'. It doesn't warn (and 
it should not).

> > -#ifndef CONFIG_BUG
> > -	return;
> > -#endif
> >  	struct wimax_dev *wimax_dev;
> >
> > +#ifdef CONFIG_BUG
>
> Did you perhaps mean ifndef here??? :-)

Sigh ... you are right ... good thing I triple checked.

Sending updated patch series.

Thanks,
Ilpo Järvinen - Jan. 7, 2009, 7:42 p.m.
On Wed, 7 Jan 2009, Inaky Perez-Gonzalez wrote:

> On Wednesday 07 January 2009, Ilpo Järvinen wrote:
> > On Tue, 6 Jan 2009, Inaky Perez-Gonzalez wrote:
> > > Reported by Randy Dunlap:
> > > > Also, this warning needs to be fixed:
> > > >
> > > > linux-next-20090106/net/wimax/id-table.c:133: warning: ISO C90
> > > > forbids mixed declarations and code
> > >
> > > Move the return on #defined(CONFIG_BUG) below the variable
> > > declarations so it doesn't violate ISO C90.
> > >
> > > On wimax_id_table_release() we want to do a debug check if CONFIG_BUG
> > > is enabled. However, we also want the debug code to be always compiled
> > > to ensure there is no bitrot.
> >
> > I hope this kind of solution won't add some warnings? Besides, this seems
> > rather strange reasoning as CONFIG_BUG is mostly enabled anyway?
> 
> Well, it is legal code -- short of 'if (1) return'. It doesn't warn (and 
> it should not).

Obviously, but I was concerned on the other lines than that 
particular one, e.g., gcc might think that wimax_dev is unused 
variable and emit a warning or along those lines...?
Inaky Perez-Gonzalez - Jan. 7, 2009, 8:57 p.m.
On Wednesday 07 January 2009, Ilpo Järvinen wrote:
> On Wed, 7 Jan 2009, Inaky Perez-Gonzalez wrote:
> > On Wednesday 07 January 2009, Ilpo Järvinen wrote:
> > > On Tue, 6 Jan 2009, Inaky Perez-Gonzalez wrote:
> > > > Reported by Randy Dunlap:
> > > > > Also, this warning needs to be fixed:
> > > > >
> > > > > linux-next-20090106/net/wimax/id-table.c:133: warning: ISO C90
> > > > > forbids mixed declarations and code
> > > >
> > > > Move the return on #defined(CONFIG_BUG) below the variable
> > > > declarations so it doesn't violate ISO C90.
> > > >
> > > > On wimax_id_table_release() we want to do a debug check if CONFIG_BUG
> > > > is enabled. However, we also want the debug code to be always
> > > > compiled to ensure there is no bitrot.
> > >
> > > I hope this kind of solution won't add some warnings? Besides, this
> > > seems rather strange reasoning as CONFIG_BUG is mostly enabled anyway?
> >
> > Well, it is legal code -- short of 'if (1) return'. It doesn't warn (and
> > it should not).
>
> Obviously, but I was concerned on the other lines than that
> particular one, e.g., gcc might think that wimax_dev is unused
> variable and emit a warning or along those lines...?

Ah, I see -- no, it won't. [disclaimer: not know much about compiler 
optimization] In theory, as we were saying, it works just as in a case 
where you have

int somevar;

if (1)
   return;

somevar = call_some_func();

with 1 being the result of a compile time evaluation. The compiler sees
that somevar is being used, but the code path is never executed, so everything
gets dumped.

If it ever did, it'd be a matter of changing that return to an if (1) return.
It'd look uglier though.

Patch

diff --git a/net/wimax/id-table.c b/net/wimax/id-table.c
index d3b8855..d6e0e8f 100644
--- a/net/wimax/id-table.c
+++ b/net/wimax/id-table.c
@@ -123,15 +123,17 @@  void wimax_id_table_rm(struct wimax_dev *wimax_dev)
 /*
  * Release the gennetlink family id / mapping table
  *
- * On debug, verify that the table is empty upon removal.
+ * On debug, verify that the table is empty upon removal. We want the
+ * code always compiled, to ensure it doesn't bit rot. It will be
+ * compiled out if CONFIG_BUG is disabled.
  */
 void wimax_id_table_release(void)
 {
-#ifndef CONFIG_BUG
-	return;
-#endif
 	struct wimax_dev *wimax_dev;
 
+#ifdef CONFIG_BUG
+	return;
+#endif
 	spin_lock(&wimax_id_table_lock);
 	list_for_each_entry(wimax_dev, &wimax_id_table, id_table_node) {
 		printk(KERN_ERR "BUG: %s wimax_dev %p ifindex %d not cleared\n",