hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ------------------ The wd (weight divisor) field in MPAM MSC registers supports values 1-16 per the MPAM specification. However, the sanity check "wd > 15" incorrectly rejects the valid wd=16 case. Fix this by checking "wd > 16" instead. Fix both percent_to_mbw_max() and mbw_max_to_percent() to use the correct boundary check and GENMASK range. Return GENMASK(15, 0) for the error case in percent_to_mbw_max() to indicate "all bits valid" rather than the misleading MAX_MBA_BW. Fixes: 58db5c68e84a ("untested: arm_mpam: resctrl: Add support for MB resource") Signed-off-by: Zeng Heng <zengheng4@huawei.com> --- drivers/platform/mpam/mpam_resctrl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index e3fd8361c22d9..a16f1318799c1 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -711,7 +711,7 @@ static u32 mbw_max_to_percent(u16 mbw_max, u8 wd) u8 bit; u32 divisor = 2, value = 0, precision = get_wd_precision(wd); - if (mbw_max == GENMASK(15, 15 - wd + 1)) + if (mbw_max == GENMASK(15, 16 - wd)) return MAX_MBA_BW; for (bit = 15; bit; bit--) { @@ -740,11 +740,12 @@ static u16 percent_to_mbw_max(u32 pc, u8 wd) u8 bit; u32 divisor = 2, value = 0, precision = get_wd_precision(wd); - if (WARN_ON_ONCE(wd > 15)) - return MAX_MBA_BW; + if (WARN_ON_ONCE(wd > 16)) + /* All bits valid as fallback */ + return GENMASK(15, 0); if (pc == MAX_MBA_BW) - return GENMASK(15, 15 - wd + 1); + return GENMASK(15, 16 - wd); pc *= precision; @@ -759,7 +760,7 @@ static u16 percent_to_mbw_max(u32 pc, u8 wd) break; } - value &= GENMASK(15, 15 - wd + 1); + value &= GENMASK(15, 16 - wd); return value; } -- 2.43.0