[PATCH next v2] phy: mediatek: fix build warning of FIELD_PREP()

Chunfeng Yun posted 1 patch 1 year, 11 months ago
drivers/phy/mediatek/phy-mtk-io.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
[PATCH next v2] phy: mediatek: fix build warning of FIELD_PREP()
Posted by Chunfeng Yun 1 year, 11 months ago
Change the inline function mtk_phy_update_field() into a macro to
avoid check warning of FIELD_PREP() with compiler parameter
-Wtautological-constant-out-of-range-compare

the warning is caused by mask check:
"BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) >     \"

Fixes: 29c07477556e ("phy: mediatek: add a new helper to update bitfield")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
v2: v1 will cause merge conflict, change comment, s/should/shall
---
 drivers/phy/mediatek/phy-mtk-io.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/mediatek/phy-mtk-io.h b/drivers/phy/mediatek/phy-mtk-io.h
index a723d4afc9b4..d20ad5e5be81 100644
--- a/drivers/phy/mediatek/phy-mtk-io.h
+++ b/drivers/phy/mediatek/phy-mtk-io.h
@@ -36,10 +36,11 @@ static inline void mtk_phy_update_bits(void __iomem *reg, u32 mask, u32 val)
 	writel(tmp, reg);
 }
 
-/* field @mask should be constant and continuous */
-static inline void mtk_phy_update_field(void __iomem *reg, u32 mask, u32 val)
-{
-	mtk_phy_update_bits(reg, mask, FIELD_PREP(mask, val));
-}
+/* field @mask shall be constant and continuous */
+#define mtk_phy_update_field(reg, mask, val) \
+({ \
+	typeof(mask) mask_ = (mask);	\
+	mtk_phy_update_bits(reg, mask_, FIELD_PREP(mask_, val)); \
+})
 
 #endif
-- 
2.18.0
Re: [PATCH next v2] phy: mediatek: fix build warning of FIELD_PREP()
Posted by Vinod Koul 1 year, 11 months ago
On 28-09-22, 15:07, Chunfeng Yun wrote:
> Change the inline function mtk_phy_update_field() into a macro to
> avoid check warning of FIELD_PREP() with compiler parameter
> -Wtautological-constant-out-of-range-compare
> 
> the warning is caused by mask check:
> "BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) >     \"

Applied, thanks

-- 
~Vinod
Re: [PATCH next v2] phy: mediatek: fix build warning of FIELD_PREP()
Posted by AngeloGioacchino Del Regno 1 year, 11 months ago
Il 28/09/22 09:07, Chunfeng Yun ha scritto:
> Change the inline function mtk_phy_update_field() into a macro to
> avoid check warning of FIELD_PREP() with compiler parameter
> -Wtautological-constant-out-of-range-compare
> 
> the warning is caused by mask check:
> "BUILD_BUG_ON_MSG(__bf_cast_unsigned(_mask, _mask) >     \"
> 
> Fixes: 29c07477556e ("phy: mediatek: add a new helper to update bitfield")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>