Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1695881 > unrolled thread

[PATCH] drm/stm: fix warning about multiplication in condition

Started byArnd Bergmann <arnd@arndb.de>
First post2017-07-25 17:50 +0200
Last post2017-07-25 18:40 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] drm/stm: fix warning about multiplication in condition Arnd Bergmann <arnd@arndb.de> - 2017-07-25 17:50 +0200
    Re: [PATCH] drm/stm: fix warning about multiplication in condition Joe Perches <joe@perches.com> - 2017-07-25 18:00 +0200
    Re: [PATCH] drm/stm: fix warning about multiplication in condition Philippe CORNU <philippe.cornu@st.com> - 2017-07-25 18:40 +0200

#1695881 — [PATCH] drm/stm: fix warning about multiplication in condition

FromArnd Bergmann <arnd@arndb.de>
Date2017-07-25 17:50 +0200
Subject[PATCH] drm/stm: fix warning about multiplication in condition
Message-ID<u7afV-4DI-45@gated-at.bofh.it>
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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/stm/dw_mipi_dsi-stm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
index 568c5d0461ea..e5b6310240fe 100644
--- a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
+++ b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
@@ -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,
-- 
2.9.0

[toc] | [next] | [standalone]


#1695893

FromJoe Perches <joe@perches.com>
Date2017-07-25 18:00 +0200
Message-ID<u7apz-4Hw-9@gated-at.bofh.it>
In reply to#1695881
On Tue, 2017-07-25 at 17:40 +0200, Arnd Bergmann wrote:
> 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.

> diff --git a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
[]
> @@ -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,

[toc] | [prev] | [next] | [standalone]


#1695934

FromPhilippe CORNU <philippe.cornu@st.com>
Date2017-07-25 18:40 +0200
Message-ID<u7b2h-59O-5@gated-at.bofh.it>
In reply to#1695881

On 07/25/2017 05:40 PM, Arnd Bergmann wrote:
> 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.

Acked-by: Philippe Cornu <philippe.cornu@st.com>
Tested-by: Philippe Cornu <philippe.cornu@st.com>

Philippe :-)

> 
> Fixes: b0f09a3c69d9 ("drm/stm: Add STM32 DSI controller driver")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   drivers/gpu/drm/stm/dw_mipi_dsi-stm.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
> index 568c5d0461ea..e5b6310240fe 100644
> --- a/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
> +++ b/drivers/gpu/drm/stm/dw_mipi_dsi-stm.c
> @@ -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,
> 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web