Re: [RFC PATCH 1/1] cleanup: use bool as return type for rwsem_is_locked
From: Peter Zijlstra
Date: Fri Jun 06 2014 - 03:35:27 EST
On Thu, Jun 05, 2014 at 04:49:37PM -0400, Pranith Kumar wrote:
> I see that there are functions like this which basically say:
>
> return 1 if true else return 0. Is it worth cleaning them up? Or is
> there any reason why this convention is followed?
Hysterical raisins, a lot of people learnt C before it grew bool,
including me.
> use bool as the return type. No reason for return type to be int.
>
> Signed-off-by: Pranith Kumar <bobby.prani@xxxxxxxxx>
> ---
> diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
> index 9be8a91..7374139 100644
> --- a/kernel/locking/rwsem-spinlock.c
> +++ b/kernel/locking/rwsem-spinlock.c
> @@ -20,7 +20,7 @@ struct rwsem_waiter {
> enum rwsem_waiter_type type;
> };
>
> -int rwsem_is_locked(struct rw_semaphore *sem)
> +bool rwsem_is_locked(struct rw_semaphore *sem)
> {
> int ret = 1;
> unsigned long flags;
Now, see that's a half arsed change, if you change the function return
value, you should also change the value we actually return, @ret above
to bool, and you should then also change the values used to 'true' and
'false'.
Now in general, I don't particularly like such superfluous changes, so
unless you can show that GCC actually generates better code, I'd prefer
to keep things as they are.
Attachment:
pgphFyD912dNN.pgp
Description: PGP signature