mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
* [PATCH] drm/meson: Cast mode->clock to unsigned long long
@ 2025-04-29 19:07 I Hsin Cheng
  2025-04-29 21:00 ` Christophe JAILLET
  0 siblings, 1 reply; 4+ messages in thread
From: I Hsin Cheng @ 2025-04-29 19:07 UTC (permalink / raw)
  To: neil.armstrong
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona,
	khilman, jbrunet, martin.blumenstingl, dri-devel, linux-amlogic,
	linux-arm-kernel, linux-kernel, skhan, I Hsin Cheng

Coverity scan reported the usage of "mode->clock * 1000" may lead to
integer overflow. Cast the type of "mode->clock" to "unsigned long long"
when utilizing it to avoid potential integer overflow issue.

Link: https://scan5.scan.coverity.com/#/project-view/10074/10063?selectedIssue=1646759
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
 drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
index 7752d8ac85f0..fe3d3ff7c432 100644
--- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c
+++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
@@ -75,7 +75,7 @@ static void meson_encoder_hdmi_set_vclk(struct meson_encoder_hdmi *encoder_hdmi,
 	unsigned long long venc_freq;
 	unsigned long long hdmi_freq;
 
-	vclk_freq = mode->clock * 1000;
+	vclk_freq = (unsigned long long) mode->clock * 1000;
 
 	/* For 420, pixel clock is half unlike venc clock */
 	if (encoder_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24)
@@ -123,7 +123,7 @@ static enum drm_mode_status meson_encoder_hdmi_mode_valid(struct drm_bridge *bri
 	struct meson_encoder_hdmi *encoder_hdmi = bridge_to_meson_encoder_hdmi(bridge);
 	struct meson_drm *priv = encoder_hdmi->priv;
 	bool is_hdmi2_sink = display_info->hdmi.scdc.supported;
-	unsigned long long clock = mode->clock * 1000;
+	unsigned long long clock = (unsigned long long) mode->clock * 1000;
 	unsigned long long phy_freq;
 	unsigned long long vclk_freq;
 	unsigned long long venc_freq;
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

* Re: [PATCH] drm/meson: Cast mode->clock to unsigned long long
  2025-04-29 19:07 [PATCH] drm/meson: Cast mode->clock to unsigned long long I Hsin Cheng
@ 2025-04-29 21:00 ` Christophe JAILLET
  2025-05-04 21:06   ` Martin Blumenstingl
  0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2025-04-29 21:00 UTC (permalink / raw)
  To: I Hsin Cheng, neil.armstrong
  Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona,
	khilman, jbrunet, martin.blumenstingl, dri-devel, linux-amlogic,
	linux-arm-kernel, linux-kernel, skhan

Le 29/04/2025 à 21:07, I Hsin Cheng a écrit :
> Coverity scan reported the usage of "mode->clock * 1000" may lead to
> integer overflow. Cast the type of "mode->clock" to "unsigned long long"
> when utilizing it to avoid potential integer overflow issue.
> 
> Link: https://scan5.scan.coverity.com/#/project-view/10074/10063?selectedIssue=1646759
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
> ---
>   drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> index 7752d8ac85f0..fe3d3ff7c432 100644
> --- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> +++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> @@ -75,7 +75,7 @@ static void meson_encoder_hdmi_set_vclk(struct meson_encoder_hdmi *encoder_hdmi,
>   	unsigned long long venc_freq;
>   	unsigned long long hdmi_freq;
>   
> -	vclk_freq = mode->clock * 1000;
> +	vclk_freq = (unsigned long long) mode->clock * 1000;

Hi,

maybe, using 1000ULL instead would do the same, but would be less verbose?

CJ

>   
>   	/* For 420, pixel clock is half unlike venc clock */
>   	if (encoder_hdmi->output_bus_fmt == MEDIA_BUS_FMT_UYYVYY8_0_5X24)
> @@ -123,7 +123,7 @@ static enum drm_mode_status meson_encoder_hdmi_mode_valid(struct drm_bridge *bri
>   	struct meson_encoder_hdmi *encoder_hdmi = bridge_to_meson_encoder_hdmi(bridge);
>   	struct meson_drm *priv = encoder_hdmi->priv;
>   	bool is_hdmi2_sink = display_info->hdmi.scdc.supported;
> -	unsigned long long clock = mode->clock * 1000;
> +	unsigned long long clock = (unsigned long long) mode->clock * 1000;
>   	unsigned long long phy_freq;
>   	unsigned long long vclk_freq;
>   	unsigned long long venc_freq;


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

* Re: [PATCH] drm/meson: Cast mode->clock to unsigned long long
  2025-04-29 21:00 ` Christophe JAILLET
@ 2025-05-04 21:06   ` Martin Blumenstingl
  2025-05-05 12:43     ` I Hsin Cheng
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Blumenstingl @ 2025-05-04 21:06 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: I Hsin Cheng, neil.armstrong, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, khilman, jbrunet, dri-devel,
	linux-amlogic, linux-arm-kernel, linux-kernel, skhan

On Tue, Apr 29, 2025 at 11:00 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> Le 29/04/2025 à 21:07, I Hsin Cheng a écrit :
> > Coverity scan reported the usage of "mode->clock * 1000" may lead to
> > integer overflow. Cast the type of "mode->clock" to "unsigned long long"
> > when utilizing it to avoid potential integer overflow issue.
> >
> > Link: https://scan5.scan.coverity.com/#/project-view/10074/10063?selectedIssue=1646759
> > Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
> > ---
> >   drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> > index 7752d8ac85f0..fe3d3ff7c432 100644
> > --- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> > +++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> > @@ -75,7 +75,7 @@ static void meson_encoder_hdmi_set_vclk(struct meson_encoder_hdmi *encoder_hdmi,
> >       unsigned long long venc_freq;
> >       unsigned long long hdmi_freq;
> >
> > -     vclk_freq = mode->clock * 1000;
> > +     vclk_freq = (unsigned long long) mode->clock * 1000;
>
> Hi,
>
> maybe, using 1000ULL instead would do the same, but would be less verbose?
Agreed, that would make the code more similar to drm_hdmi_compute_mode_clock().
The goal is to switch to drm_hdmi_compute_mode_clock() mid-term anyways.

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

* Re: [PATCH] drm/meson: Cast mode->clock to unsigned long long
  2025-05-04 21:06   ` Martin Blumenstingl
@ 2025-05-05 12:43     ` I Hsin Cheng
  0 siblings, 0 replies; 4+ messages in thread
From: I Hsin Cheng @ 2025-05-05 12:43 UTC (permalink / raw)
  To: Martin Blumenstingl
  Cc: Christophe JAILLET, neil.armstrong, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, khilman, jbrunet, dri-devel,
	linux-amlogic, linux-arm-kernel, linux-kernel, skhan

On Sun, May 04, 2025 at 11:06:06PM +0200, Martin Blumenstingl wrote:
> On Tue, Apr 29, 2025 at 11:00 PM Christophe JAILLET
> <christophe.jaillet@wanadoo.fr> wrote:
> >
> > Le 29/04/2025 à 21:07, I Hsin Cheng a écrit :
> > > Coverity scan reported the usage of "mode->clock * 1000" may lead to
> > > integer overflow. Cast the type of "mode->clock" to "unsigned long long"
> > > when utilizing it to avoid potential integer overflow issue.
> > >
> > > Link: https://scan5.scan.coverity.com/#/project-view/10074/10063?selectedIssue=1646759
> > > Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
> > > ---
> > >   drivers/gpu/drm/meson/meson_encoder_hdmi.c | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/meson/meson_encoder_hdmi.c b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> > > index 7752d8ac85f0..fe3d3ff7c432 100644
> > > --- a/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> > > +++ b/drivers/gpu/drm/meson/meson_encoder_hdmi.c
> > > @@ -75,7 +75,7 @@ static void meson_encoder_hdmi_set_vclk(struct meson_encoder_hdmi *encoder_hdmi,
> > >       unsigned long long venc_freq;
> > >       unsigned long long hdmi_freq;
> > >
> > > -     vclk_freq = mode->clock * 1000;
> > > +     vclk_freq = (unsigned long long) mode->clock * 1000;
> >
> > Hi,
> >
> > maybe, using 1000ULL instead would do the same, but would be less verbose?
> Agreed, that would make the code more similar to drm_hdmi_compute_mode_clock().
> The goal is to switch to drm_hdmi_compute_mode_clock() mid-term anyways.

Hi,

Thanks for your review and suggestions !
I'll make the corresponding changes and send v2.

Best regards,
I Hsin Cheng


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

end of thread, other threads:[~2025-05-05 13:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-29 19:07 [PATCH] drm/meson: Cast mode->clock to unsigned long long I Hsin Cheng
2025-04-29 21:00 ` Christophe JAILLET
2025-05-04 21:06   ` Martin Blumenstingl
2025-05-05 12:43     ` I Hsin Cheng

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

all inboxes | Powered by JetHome®