diff mbox series

drm/bridge/synopsys: avoid field overflow warning

Message ID 20250408175116.1770876-1-arnd@kernel.org (mailing list archive)
State New, archived
Headers show
Series drm/bridge/synopsys: avoid field overflow warning | expand

Commit Message

Arnd Bergmann April 8, 2025, 5:51 p.m. UTC
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(-)

Comments

Arnd Bergmann April 9, 2025, 7:07 a.m. UTC | #1
On Tue, Apr 8, 2025, at 19:51, Arnd Bergmann wrote:
> 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 still see the same build failure in some other configurations even
with this patch. Please disregard this version, I'll try to come
up with a better one.

       Arnd
Arnd Bergmann April 10, 2025, 12:36 p.m. UTC | #2
On Wed, Apr 9, 2025, at 09:07, Arnd Bergmann wrote:
> On Tue, Apr 8, 2025, at 19:51, Arnd Bergmann wrote:
>> 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 still see the same build failure in some other configurations even
> with this patch. Please disregard this version, I'll try to come
> up with a better one.

I couldn't come up with anything that actually worked, other than
the hack below, which just works around the compiletime error
in FIELD_PREP(), but doesn't look like a proper fix.

If anyone else has any ideas, I can test their patch.

       Arnd

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c
index c76f5f2e74d1..8ba528462ede 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c
@@ -344,7 +344,7 @@ static void dw_mipi_dsi2_phy_ratio_cfg(struct dw_mipi_dsi2 *dsi2)
         */
        tmp = DIV_ROUND_CLOSEST_ULL(phy_hsclk << 16, sys_clk);
        regmap_write(dsi2->regmap, DSI2_PHY_SYS_RATIO_MAN_CFG,
-                    PHY_SYS_RATIO(tmp));
+                    PHY_SYS_RATIO(tmp & GENMASK(16, 0)));
 }
 
 static void dw_mipi_dsi2_lp2hs_or_hs2lp_cfg(struct dw_mipi_dsi2 *dsi2)
diff mbox series

Patch

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));
 }