* [PATCH] drm/stm: fix warning about multiplication in condition
@ 2017-07-25 15:40 ` Arnd Bergmann
0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2017-07-25 15:40 UTC (permalink / raw)
To: Yannick Fertre, Philippe Cornu, Benjamin Gaignard, Vincent Abriou,
David Airlie
Cc: linux-kernel, dri-devel, Arnd Bergmann, Neil Armstrong
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
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] drm/stm: fix warning about multiplication in condition
@ 2017-07-25 15:40 ` Arnd Bergmann
0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2017-07-25 15:40 UTC (permalink / raw)
To: Yannick Fertre, Philippe Cornu, Benjamin Gaignard, Vincent Abriou,
David Airlie
Cc: Arnd Bergmann, Neil Armstrong, Archit Taneja, dri-devel,
linux-kernel
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/stm: fix warning about multiplication in condition
2017-07-25 15:40 ` Arnd Bergmann
@ 2017-07-25 15:52 ` Joe Perches
-1 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2017-07-25 15:52 UTC (permalink / raw)
To: Arnd Bergmann, Yannick Fertre, Philippe Cornu, Benjamin Gaignard,
Vincent Abriou, David Airlie
Cc: linux-kernel, dri-devel, Neil Armstrong
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,
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/stm: fix warning about multiplication in condition
@ 2017-07-25 15:52 ` Joe Perches
0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2017-07-25 15:52 UTC (permalink / raw)
To: Arnd Bergmann, Yannick Fertre, Philippe Cornu, Benjamin Gaignard,
Vincent Abriou, David Airlie
Cc: Neil Armstrong, Archit Taneja, dri-devel, linux-kernel
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,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/stm: fix warning about multiplication in condition
2017-07-25 15:40 ` Arnd Bergmann
@ 2017-07-25 16:29 ` Philippe CORNU
-1 siblings, 0 replies; 6+ messages in thread
From: Philippe CORNU @ 2017-07-25 16:29 UTC (permalink / raw)
To: Arnd Bergmann, Yannick FERTRE, Benjamin Gaignard, Vincent ABRIOU,
David Airlie
Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
Neil Armstrong
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,
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/stm: fix warning about multiplication in condition
@ 2017-07-25 16:29 ` Philippe CORNU
0 siblings, 0 replies; 6+ messages in thread
From: Philippe CORNU @ 2017-07-25 16:29 UTC (permalink / raw)
To: Arnd Bergmann, Yannick FERTRE, Benjamin Gaignard, Vincent ABRIOU,
David Airlie
Cc: Neil Armstrong, Archit Taneja, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
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,
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-07-25 16:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 15:40 [PATCH] drm/stm: fix warning about multiplication in condition Arnd Bergmann
2017-07-25 15:40 ` Arnd Bergmann
2017-07-25 15:52 ` Joe Perches
2017-07-25 15:52 ` Joe Perches
2017-07-25 16:29 ` Philippe CORNU
2017-07-25 16:29 ` Philippe CORNU
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.