Skip to contentSkip to conversation

drm/stm: fix warning about multiplication in condition

PATCH Superseded Arnd Bergmann 3 participants 3 messages Jul 25, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/stm: fix warning about multiplication in condition

gcc-7 complains about multiplying within a condition being suspicious:

drivers/gpu/drm/stm/dw_mipi_dsi-stm.c: In function 'dsi_pll_get_clkout_khz':
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c:117:10: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]

The code here is correct, but can be easily rephrased to make that more obvious. I also swap out the error handling and the normal code path for clarity.

Fixes b0f09a3c69d9 ("drm/stm: Add STM32 DSI controller driver")
---
 drivers/gpu/drm/stm/dw_mipi_dsi-stm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +5 -3
index 568c5d0461ea..e5b6310240fe 100644
@@ -113,11 +113,13 @@ static enum dsi_color dsi_color_from_mipi(enum mipi_dsi_pixel_format fmt)
 
 static int dsi_pll_get_clkout_khz(int clkin_khz, int idf, int ndiv, int odf)
 {
+	int divisor = idf * odf;
+
 	/* prevent from division by 0 */
-	if (idf * odf)
-		return DIV_ROUND_CLOSEST(clkin_khz * ndiv, idf * odf);
+	if (!divisor)
+		return 0;
 
-	return 0;
+	return DIV_ROUND_CLOSEST(clkin_khz * ndiv, divisor);
 }
 
 static int dsi_pll_get_params(int clkin_khz, int clkout_khz,
Signature · 6 lines
2.9.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 9 lines · Arnd Bergmann

gcc-7 complains about multiplying within a condition being suspicious:

drivers/gpu/drm/stm/dw_mipi_dsi-stm.c: In function 'dsi_pll_get_clkout_khz':
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c:117:10: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]

The code here is correct, but can be easily rephrased to make that more obvious. I also swap out the error handling and the normal code path for clarity.

Thanks, the new code does read much better.

drivers/gpu/drm/stm/dw_mipi_dsi-stm.c

Quoted 1 line
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +0 -0

[]

Quoted 7 lines
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +2 -0
@@ -113,11 +113,13 @@ static enum dsi_color dsi_color_from_mipi(enum mipi_dsi_pixel_format fmt)
 
 static int dsi_pll_get_clkout_khz(int clkin_khz, int idf, int ndiv, int odf)
 {
+	int divisor = idf * odf;
+
 	/* prevent from division by 0 */

drivers/gpu/drm/stm/dw_mipi_dsi-stm.c static enum dsi_color dsi_color_from_mipi(enum mipi_dsi_pixel_format fmt) · line 125

Quoted 10 lines
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +3 -3
-	if (idf * odf)
-		return DIV_ROUND_CLOSEST(clkin_khz * ndiv, idf * odf);
+	if (!divisor)
+		return 0;
 
-	return 0;
+	return DIV_ROUND_CLOSEST(clkin_khz * ndiv, divisor);
 }
 
 static int dsi_pll_get_params(int clkin_khz, int clkout_khz,

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Acked-by Tested-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

gcc-7 complains about multiplying within a condition being suspicious:

drivers/gpu/drm/stm/dw_mipi_dsi-stm.c: In function 'dsi_pll_get_clkout_khz':
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c:117:10: error: '*' in boolean context, suggest '&&' instead [-Werror=int-in-bool-context]

The code here is correct, but can be easily rephrased to make that more obvious. I also swap out the error handling and the normal code path for clarity.

Hi Arnd,
And many thanks for this new & much better code.

Philippe :-)

Quoted 19 lines
Fixes b0f09a3c69d9 ("drm/stm: Add STM32 DSI controller driver")
---
  drivers/gpu/drm/stm/dw_mipi_dsi-stm.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +2 -0
index 568c5d0461ea..e5b6310240fe 100644
@@ -113,11 +113,13 @@ static enum dsi_color dsi_color_from_mipi(enum mipi_dsi_pixel_format fmt)
 
  static int dsi_pll_get_clkout_khz(int clkin_khz, int idf, int ndiv, int odf)
  {
+	int divisor = idf * odf;
+
  	/* prevent from division by 0 */

drivers/gpu/drm/stm/dw_mipi_dsi-stm.c static enum dsi_color dsi_color_from_mipi(enum mipi_dsi_pixel_format fmt) · line 125

Quoted 10 lines
drivers/gpu/drm/stm/dw_mipi_dsi-stm.c +3 -3
-	if (idf * odf)
-		return DIV_ROUND_CLOSEST(clkin_khz * ndiv, idf * odf);
+	if (!divisor)
+		return 0;
 
-	return 0;
+	return DIV_ROUND_CLOSEST(clkin_khz * ndiv, divisor);
  }
 
  static int dsi_pll_get_params(int clkin_khz, int clkout_khz,

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel