Re: [net-next PATCH 04/10] bitfield.h: add FIELD_WIDTH()
From: David Laight
Date: Sat Apr 04 2026 - 10:54:38 EST
On Fri, 3 Apr 2026 11:09:30 -0300
Luiz Angelo Daros de Luca <luizluca@xxxxxxxxx> wrote:
> Thanks David and Yuri,
>
> This patch was originally intended to reconstruct a value split across
> multiple registers. Originally:
>
> vlan4k->member =
> FIELD_GET(RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK, data[0]) |
> (FIELD_GET(RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK, data[2])
> << FIELD_WIDTH(RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK));
>
> However, as Yuri pointed out, I can use FIELD_PREP() to align the bits
> into the final struct member without manual bitops. While less common,
> this pattern is used elsewhere (e.g., drivers/clk/clk-lmk04832.c). The
> updated approach would be:
>
> vlan4k->member =
> FIELD_PREP(RTL8365MB_CVLAN_MBR_LO_MASK,
> FIELD_GET(RTL8365MB_CVLAN_ENTRY_D0_MBR_MASK,
> data[0])) |
> FIELD_PREP(RTL8365MB_CVLAN_MBR_HI_MASK,
>
> FIELD_GET(RTL8365MB_CVLAN_ENTRY_D2_MBR_EXT_MASK, data[2]));
Q: does the line make any sense to someone reading the code?
I'd also generate the .i file and look at output first.
You might find the line doesn't fit on your screen.
David
>
> If this use of FIELD_PREP is preferred, I will drop this FIELD_WIDTH
> patch from the series as it would no longer have any users.
>
> Regards,
>
> Luiz