[PATCH net-next v1 7/7] net: hsr: use BIT() macro for bit shift constant

luka.gejak@linux.dev posted 7 patches 1 week, 2 days ago
There is a newer version of this series
[PATCH net-next v1 7/7] net: hsr: use BIT() macro for bit shift constant
Posted by luka.gejak@linux.dev 1 week, 2 days ago
From: Luka Gejak <luka.gejak@linux.dev>

Replace the explicit bit shift (1 << HSR_SEQ_BLOCK_SHIFT) with the
standardized BIT() macro for defining HSR_SEQ_BLOCK_SIZE. This improves
readability and aligns with kernel coding conventions.

Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
 net/hsr/hsr_framereg.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index c65ecb925734..cb731ee0ce5c 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -79,7 +79,7 @@ struct hsr_seq_block *hsr_get_seq_block(struct hsr_node *node, u16 block_idx);
 #endif
 
 #define HSR_SEQ_BLOCK_SHIFT 7 /* 128 bits */
-#define HSR_SEQ_BLOCK_SIZE (1 << HSR_SEQ_BLOCK_SHIFT)
+#define HSR_SEQ_BLOCK_SIZE BIT(HSR_SEQ_BLOCK_SHIFT)
 #define HSR_SEQ_BLOCK_MASK (HSR_SEQ_BLOCK_SIZE - 1)
 #define HSR_MAX_SEQ_BLOCKS 64
 
-- 
2.53.0
Re: [PATCH net-next v1 7/7] net: hsr: use BIT() macro for bit shift constant
Posted by Felix Maurer 1 week ago
On Tue, Mar 24, 2026 at 03:46:30PM +0100, luka.gejak@linux.dev wrote:
> From: Luka Gejak <luka.gejak@linux.dev>
>
> Replace the explicit bit shift (1 << HSR_SEQ_BLOCK_SHIFT) with the
> standardized BIT() macro for defining HSR_SEQ_BLOCK_SIZE. This improves
> readability and aligns with kernel coding conventions.

I know that checkpatch suggests this, but I don't agree with it:
HSR_SEQ_BLOCK_SHIFT is not a bitmap but a number, so in my opinion the
BIT() macro makes this particular define harder to read/understand.

> Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
> ---
>  net/hsr/hsr_framereg.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
> index c65ecb925734..cb731ee0ce5c 100644
> --- a/net/hsr/hsr_framereg.h
> +++ b/net/hsr/hsr_framereg.h
> @@ -79,7 +79,7 @@ struct hsr_seq_block *hsr_get_seq_block(struct hsr_node *node, u16 block_idx);
>  #endif
>
>  #define HSR_SEQ_BLOCK_SHIFT 7 /* 128 bits */
> -#define HSR_SEQ_BLOCK_SIZE (1 << HSR_SEQ_BLOCK_SHIFT)
> +#define HSR_SEQ_BLOCK_SIZE BIT(HSR_SEQ_BLOCK_SHIFT)
>  #define HSR_SEQ_BLOCK_MASK (HSR_SEQ_BLOCK_SIZE - 1)
>  #define HSR_MAX_SEQ_BLOCKS 64
>
> --
> 2.53.0
>