Re: [net-next PATCH 04/10] bitfield.h: add FIELD_WIDTH()
From: Luiz Angelo Daros de Luca
Date: Fri Apr 03 2026 - 10:16:40 EST
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]));
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