public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rcu: change function declaration to bool
@ 2015-05-11  8:51 Nicholas Mc Guire
  2015-05-11 14:40 ` Josh Triplett
  0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Mc Guire @ 2015-05-11  8:51 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Josh Triplett, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan,
	linux-kernel, Nicholas Mc Guire

rcu_cpu_has_callbacks() is declared int but is actually returning bool and
all call-sites currently use it as bool so the declaration should be bool 
as well.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

./kernel/rcu/tree.c:3538 WARNING: return of wrong type
                    int != bool, 

as the description of rcu_cpu_has_callbacks() states:
" * Return true if the specified CPU has any callback...."
this probably should be a bool 
All (3) call sites are conditions and are treating it as boolean.

Patch was compile tested with x86_64_defconfig (implies CONFIG_TREE_RCU=y)

Patch is against 4.1-rc3 (localversion-next is -next-20150511)

 kernel/rcu/tree.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index bcc5943..599550c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3516,7 +3516,7 @@ static int rcu_pending(void)
  * non-NULL, store an indication of whether all callbacks are lazy.
  * (If there are no callbacks, all of them are deemed to be lazy.)
  */
-static int __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy)
+static bool __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy)
 {
 	bool al = true;
 	bool hc = false;
-- 
1.7.10.4


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

* Re: [PATCH] rcu: change function declaration to bool
  2015-05-11  8:51 [PATCH] rcu: change function declaration to bool Nicholas Mc Guire
@ 2015-05-11 14:40 ` Josh Triplett
  2015-05-11 15:19   ` Nicholas Mc Guire
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Triplett @ 2015-05-11 14:40 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Paul E. McKenney, Steven Rostedt, Mathieu Desnoyers,
	Lai Jiangshan, linux-kernel

On Mon, May 11, 2015 at 10:51:55AM +0200, Nicholas Mc Guire wrote:
> rcu_cpu_has_callbacks() is declared int but is actually returning bool and
> all call-sites currently use it as bool so the declaration should be bool 
> as well.
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>

The patch seems reasonable to me.  However...

> ---
> 
> ./kernel/rcu/tree.c:3538 WARNING: return of wrong type
>                     int != bool, 
> 
> as the description of rcu_cpu_has_callbacks() states:
> " * Return true if the specified CPU has any callback...."
> this probably should be a bool 
> All (3) call sites are conditions and are treating it as boolean.
> 
> Patch was compile tested with x86_64_defconfig (implies CONFIG_TREE_RCU=y)

...some of this information should be in the commit message, as well as
a description of what tool produced this warning.

With that changed,
Reviewed-by: Josh Triplett <josh@joshtriplett.org>

> Patch is against 4.1-rc3 (localversion-next is -next-20150511)
> 
>  kernel/rcu/tree.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index bcc5943..599550c 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -3516,7 +3516,7 @@ static int rcu_pending(void)
>   * non-NULL, store an indication of whether all callbacks are lazy.
>   * (If there are no callbacks, all of them are deemed to be lazy.)
>   */
> -static int __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy)
> +static bool __maybe_unused rcu_cpu_has_callbacks(bool *all_lazy)
>  {
>  	bool al = true;
>  	bool hc = false;
> -- 
> 1.7.10.4
> 

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

* Re: [PATCH] rcu: change function declaration to bool
  2015-05-11 14:40 ` Josh Triplett
@ 2015-05-11 15:19   ` Nicholas Mc Guire
  0 siblings, 0 replies; 3+ messages in thread
From: Nicholas Mc Guire @ 2015-05-11 15:19 UTC (permalink / raw)
  To: Josh Triplett
  Cc: Nicholas Mc Guire, Paul E. McKenney, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, linux-kernel

On Mon, 11 May 2015, Josh Triplett wrote:

> On Mon, May 11, 2015 at 10:51:55AM +0200, Nicholas Mc Guire wrote:
> > rcu_cpu_has_callbacks() is declared int but is actually returning bool and
> > all call-sites currently use it as bool so the declaration should be bool 
> > as well.
> > 
> > Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> 
> The patch seems reasonable to me.  However...
> 
> > ---
> > 
> > ./kernel/rcu/tree.c:3538 WARNING: return of wrong type
> >                     int != bool, 
> > 
> > as the description of rcu_cpu_has_callbacks() states:
> > " * Return true if the specified CPU has any callback...."
> > this probably should be a bool 
> > All (3) call sites are conditions and are treating it as boolean.
> > 
> > Patch was compile tested with x86_64_defconfig (implies CONFIG_TREE_RCU=y)
> 
> ...some of this information should be in the commit message, as well as
> a description of what tool produced this warning.
>

The tool is coccinelle - type checking scripts that Im working on and that
produced (with Julia Lawal fixing up my .cocci scripts) a few 1000s of 
type missmatches in the overall kernel a few hundred in the ./kernel/* - 
so starting to clean up....
 
> With that changed,
> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
>

thanks - just resend with description moved. and a note that coccinelle was
used.

The full script is though in its current form not yet usable as it is not 
classifying type errors - had to do that manually - for the kernel (and 
glibc for comparison) this is currently:

component  Nr funcs  != type    %
kernel   :  374600    10727    2.85
glibc    :    9184      268    2.92

finding                  kernel  glibc 
wrong ?                :     8     4   
sign missmatch         :  2279    30   
down sized             :   435    49   
up sized               :   910    20   
declaration missmatch  :  7095   165   

as noted - sorting/filtering needed some manual work so nubers
are not that precise. wrong here simply means I could not figure
it out like an int foo() returning a float.

Once this is cleaned up I'll post the type-checking scripts along with
the depressing results...

// Find functions where return type and signature do not match
// V2: with the suggestions/improvements from Julia Lawal added this
// now finds about 10 times as many bad cases ...                               
//
// Comments:
// Options: --no-includes --include-headers

virtual context
virtual org
virtual report

@match exists@
type T1,T2;
idexpression T1 ok;
idexpression T2 ret;
identifier f;
constant C;
position p;
@@

T1 f(...) {
<+...
(
return ok;
|
return C;
|
return@p ret;
)
...+>
}

@script:python@
p << match.p;
fn << match.f;
T1 << match.T1;
T2 << match.T2;
@@

print "%s:%s WARNING: return of wrong type \n\t %s != %s" % (p[0].file,p[0].line,T1,T2)
 

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

end of thread, other threads:[~2015-05-11 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-11  8:51 [PATCH] rcu: change function declaration to bool Nicholas Mc Guire
2015-05-11 14:40 ` Josh Triplett
2015-05-11 15:19   ` Nicholas Mc Guire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox