[PATCH v5 1/6] clk: correct clk_div_mask() return value for width == 32
Troy Mitchell
troy.mitchell at linux.spacemit.com
Sun May 17 22:58:45 PDT 2026
On Thu May 14, 2026 at 5:27 PM CST, Junhui Liu wrote:
> The macro clk_div_mask() currently wraps to zero when width is 32 due to
> 1 << 32 being undefined behavior. This leads to incorrect mask generation
> and prevents correct retrieval of register field values for 32-bit-wide
> dividers.
>
> Although it is unlikely to exhaust all U32_MAX div, some clock IPs may rely
> on a 32-bit val entry in their div_table to match a div, so providing a
> full 32-bit mask is necessary.
>
> Fix this by using the standard GENMASK() macro. This safely resolves the
> undefined behavior on both 32-bit and 64-bit architectures, while also
> benefiting from the built-in compile-time type and bounds checking
> provided by the GENMASK() macro.
>
> Cc: Troy Mitchell <troy.mitchell at linux.spacemit.com>
> Cc: Brian Masney <bmasney at redhat.com>
> Signed-off-by: Junhui Liu <junhui.liu at pigmoral.tech>
>
> ---
> Hi Troy and Brian, I dropped your Reviewed-by tags in this version
> because the implementation has changed (to use GENMASK()) and requires
> re-evaluation IMO.
Reviewed-by: Troy Mitchell <troy.mitchell at linux.spacemit.com>
More information about the linux-riscv
mailing list