public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/bridge/synopsys: avoid field overflow warning
@ 2025-04-08 17:51 Arnd Bergmann
  2025-04-09  7:07 ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2025-04-08 17:51 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Nathan Chancellor, Heiko Stuebner, Andy Yan
  Cc: Arnd Bergmann, Laurent Pinchart, Jonas Karlman, Jernej Skrabec,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Dmitry Baryshkov,
	Douglas Anderson, dri-devel, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

clang-16 and earlier complain about what it thinks might be an out of
range number:

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c:348:8: error: call to __compiletime_assert_579 declared with 'error' attribute: FIELD_PREP: value too large for the field
                     PHY_SYS_RATIO(tmp));
                     ^
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c:90:27: note: expanded from macro 'PHY_SYS_RATIO'
 #define PHY_SYS_RATIO(x)                FIELD_PREP(GENMASK(16, 0), x)

I could not figure out if that overflow is actually possible or not,
but truncating the range to the maximum value avoids the warning and
probably can't hurt.

Fixes: 0d6d86253fef ("drm/bridge/synopsys: Add MIPI DSI2 host controller bridge")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c
index 5fd7a459efdd..440b9a71012f 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c
@@ -342,7 +342,7 @@ static void dw_mipi_dsi2_phy_ratio_cfg(struct dw_mipi_dsi2 *dsi2)
 	/*
 	 * SYS_RATIO_MAN_CFG = MIPI_DCPHY_HSCLK_Freq / MIPI_DCPHY_HSCLK_Freq
 	 */
-	tmp = DIV_ROUND_CLOSEST_ULL(phy_hsclk << 16, sys_clk);
+	tmp = min(DIV_ROUND_CLOSEST_ULL(phy_hsclk << 16, sys_clk), GENMASK(16, 0));
 	regmap_write(dsi2->regmap, DSI2_PHY_SYS_RATIO_MAN_CFG,
 		     PHY_SYS_RATIO(tmp));
 }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-07 14:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-08 17:51 [PATCH] drm/bridge/synopsys: avoid field overflow warning Arnd Bergmann
2025-04-09  7:07 ` Arnd Bergmann
2025-04-10 12:36   ` Arnd Bergmann
2025-05-07  9:06     ` Borislav Petkov
2025-05-07 14:34     ` Heiko Stübner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox