linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] rcu: change return type to bool
@ 2015-05-27  6:56 Nicholas Mc Guire
  2015-05-27 21:19 ` Paul E. McKenney
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2015-05-27  6:56 UTC (permalink / raw)
  To: Lai Jiangshan
  Cc: Paul E. McKenney, Josh Triplett, Steven Rostedt, Joe Perches,
	Mathieu Desnoyers, linux-kernel, Nicholas Mc Guire

Type-checking coccinelle spatches are being used to locate type mismatches
between function signatures and return values in this case this produced:
./kernel/rcu/srcu.c:271 WARNING: return of wrong type
        int != unsigned long,

srcu_readers_active() returns an int that is the sum of per_cpu unsigned
long but the only user is cleanup_srcu_struct() which is using it as a
boolean (condition) to see if there is any readers rather than actually
using the approximate number of readers. The theoretically possible
unsigned long overflow case does not need to be handled explicitly - if
we had 4G++ readers then something else went wrong a long time ago.

proposal: change the return type to boolean. The function name is left
          unchanged as it fits the naming expectation for a boolean.

patch was compile tested for x86_64_defconfig (implies CONFIG_SRCU=y)

patch is against 4.1-rc5 (localversion-next is -next-20150525)

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

V2: dropped the unnecessary !! conversion to boolean. for the details
    see Joe Perches <joe@perches.com> clarification at
    http://lkml.org/lkml/2015/5/24/47

 kernel/rcu/srcu.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
index fb33d35..de35087 100644
--- a/kernel/rcu/srcu.c
+++ b/kernel/rcu/srcu.c
@@ -252,14 +252,15 @@ static bool srcu_readers_active_idx_check(struct srcu_struct *sp, int idx)
 }
 
 /**
- * srcu_readers_active - returns approximate number of readers.
+ * srcu_readers_active - returns true if there are readers. and false
+ *                       otherwise
  * @sp: which srcu_struct to count active readers (holding srcu_read_lock).
  *
  * Note that this is not an atomic primitive, and can therefore suffer
  * severe errors when invoked on an active srcu_struct.  That said, it
  * can be useful as an error check at cleanup time.
  */
-static int srcu_readers_active(struct srcu_struct *sp)
+static bool srcu_readers_active(struct srcu_struct *sp)
 {
 	int cpu;
 	unsigned long sum = 0;
-- 
1.7.10.4


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

* Re: [PATCH V2] rcu: change return type to bool
  2015-05-27  6:56 [PATCH V2] rcu: change return type to bool Nicholas Mc Guire
@ 2015-05-27 21:19 ` Paul E. McKenney
  0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2015-05-27 21:19 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Lai Jiangshan, Josh Triplett, Steven Rostedt, Joe Perches,
	Mathieu Desnoyers, linux-kernel

On Wed, May 27, 2015 at 08:56:25AM +0200, Nicholas Mc Guire wrote:
> Type-checking coccinelle spatches are being used to locate type mismatches
> between function signatures and return values in this case this produced:
> ./kernel/rcu/srcu.c:271 WARNING: return of wrong type
>         int != unsigned long,
> 
> srcu_readers_active() returns an int that is the sum of per_cpu unsigned
> long but the only user is cleanup_srcu_struct() which is using it as a
> boolean (condition) to see if there is any readers rather than actually
> using the approximate number of readers. The theoretically possible
> unsigned long overflow case does not need to be handled explicitly - if
> we had 4G++ readers then something else went wrong a long time ago.
> 
> proposal: change the return type to boolean. The function name is left
>           unchanged as it fits the naming expectation for a boolean.
> 
> patch was compile tested for x86_64_defconfig (implies CONFIG_SRCU=y)
> 
> patch is against 4.1-rc5 (localversion-next is -next-20150525)
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>

OK, I have queued this for testing.  If Lai Jiangshan is OK with it,
I am OK with it.

							Thanx, Paul

> ---
> 
> V2: dropped the unnecessary !! conversion to boolean. for the details
>     see Joe Perches <joe@perches.com> clarification at
>     http://lkml.org/lkml/2015/5/24/47
> 
>  kernel/rcu/srcu.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
> index fb33d35..de35087 100644
> --- a/kernel/rcu/srcu.c
> +++ b/kernel/rcu/srcu.c
> @@ -252,14 +252,15 @@ static bool srcu_readers_active_idx_check(struct srcu_struct *sp, int idx)
>  }
> 
>  /**
> - * srcu_readers_active - returns approximate number of readers.
> + * srcu_readers_active - returns true if there are readers. and false
> + *                       otherwise
>   * @sp: which srcu_struct to count active readers (holding srcu_read_lock).
>   *
>   * Note that this is not an atomic primitive, and can therefore suffer
>   * severe errors when invoked on an active srcu_struct.  That said, it
>   * can be useful as an error check at cleanup time.
>   */
> -static int srcu_readers_active(struct srcu_struct *sp)
> +static bool srcu_readers_active(struct srcu_struct *sp)
>  {
>  	int cpu;
>  	unsigned long sum = 0;
> -- 
> 1.7.10.4
> 


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-27  6:56 [PATCH V2] rcu: change return type to bool Nicholas Mc Guire
2015-05-27 21:19 ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).