diff mbox series

[-next] rcu: Use the BITS_PER_LONG macro

Message ID 20240902110654.2685917-1-ruanjinjie@huawei.com (mailing list archive)
State Accepted
Commit a7293f0998a24344755fa69af5717055f20e5eaf
Headers show
Series [-next] rcu: Use the BITS_PER_LONG macro | expand

Commit Message

Jinjie Ruan Sept. 2, 2024, 11:06 a.m. UTC
sizeof(unsigned long) * 8 is the number of bits in an unsigned long
variable, replace it with BITS_PER_LONG macro to make it simpler.

Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
 kernel/rcu/tree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Mathieu Desnoyers Sept. 2, 2024, 12:16 p.m. UTC | #1
On 2024-09-02 07:06, Jinjie Ruan wrote:
> sizeof(unsigned long) * 8 is the number of bits in an unsigned long
> variable, replace it with BITS_PER_LONG macro to make it simpler.

An alternative would be:

if (rcu_fanout_leaf < 2 || sizeof_field(struct rcu_node, qsmask) * CHAR_BIT) {

which would then tie the check to validated member type. But it's
slightly more verbose, so it's up to the maintainer really.

Thanks,

Mathieu

> 
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
>   kernel/rcu/tree.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index a60616e69b66..b48864df415c 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -5579,8 +5579,7 @@ void rcu_init_geometry(void)
>   	 * Complain and fall back to the compile-time values if this
>   	 * limit is exceeded.
>   	 */
> -	if (rcu_fanout_leaf < 2 ||
> -	    rcu_fanout_leaf > sizeof(unsigned long) * 8) {
> +	if (rcu_fanout_leaf < 2 || rcu_fanout_leaf > BITS_PER_LONG) {
>   		rcu_fanout_leaf = RCU_FANOUT_LEAF;
>   		WARN_ON(1);
>   		return;
Jinjie Ruan Sept. 3, 2024, 3:50 a.m. UTC | #2
On 2024/9/2 20:16, Mathieu Desnoyers wrote:
> On 2024-09-02 07:06, Jinjie Ruan wrote:
>> sizeof(unsigned long) * 8 is the number of bits in an unsigned long
>> variable, replace it with BITS_PER_LONG macro to make it simpler.
> 
> An alternative would be:
> 
> if (rcu_fanout_leaf < 2 || sizeof_field(struct rcu_node, qsmask) *
> CHAR_BIT) {
> 
> which would then tie the check to validated member type. But it's
> slightly more verbose, so it's up to the maintainer really.

Yes, it reflects the original purpose but it is too long.

> 
> Thanks,
> 
> Mathieu
> 
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>   kernel/rcu/tree.c | 3 +--
>>   1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
>> index a60616e69b66..b48864df415c 100644
>> --- a/kernel/rcu/tree.c
>> +++ b/kernel/rcu/tree.c
>> @@ -5579,8 +5579,7 @@ void rcu_init_geometry(void)
>>        * Complain and fall back to the compile-time values if this
>>        * limit is exceeded.
>>        */
>> -    if (rcu_fanout_leaf < 2 ||
>> -        rcu_fanout_leaf > sizeof(unsigned long) * 8) {
>> +    if (rcu_fanout_leaf < 2 || rcu_fanout_leaf > BITS_PER_LONG) {
>>           rcu_fanout_leaf = RCU_FANOUT_LEAF;
>>           WARN_ON(1);
>>           return;
>
Paul E. McKenney Sept. 3, 2024, 10:28 a.m. UTC | #3
On Mon, Sep 02, 2024 at 07:06:54PM +0800, Jinjie Ruan wrote:
> sizeof(unsigned long) * 8 is the number of bits in an unsigned long
> variable, replace it with BITS_PER_LONG macro to make it simpler.
> 
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>

Either Jinjie's or Mathieu's formulation works for me.  But Jinjie was
here first, so:

Reviewed-by: Paul E. McKenney <paulmck@kernel.org>

> ---
>  kernel/rcu/tree.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index a60616e69b66..b48864df415c 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -5579,8 +5579,7 @@ void rcu_init_geometry(void)
>  	 * Complain and fall back to the compile-time values if this
>  	 * limit is exceeded.
>  	 */
> -	if (rcu_fanout_leaf < 2 ||
> -	    rcu_fanout_leaf > sizeof(unsigned long) * 8) {
> +	if (rcu_fanout_leaf < 2 || rcu_fanout_leaf > BITS_PER_LONG) {
>  		rcu_fanout_leaf = RCU_FANOUT_LEAF;
>  		WARN_ON(1);
>  		return;
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index a60616e69b66..b48864df415c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -5579,8 +5579,7 @@  void rcu_init_geometry(void)
 	 * Complain and fall back to the compile-time values if this
 	 * limit is exceeded.
 	 */
-	if (rcu_fanout_leaf < 2 ||
-	    rcu_fanout_leaf > sizeof(unsigned long) * 8) {
+	if (rcu_fanout_leaf < 2 || rcu_fanout_leaf > BITS_PER_LONG) {
 		rcu_fanout_leaf = RCU_FANOUT_LEAF;
 		WARN_ON(1);
 		return;