public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast
@ 2023-05-16 17:30 Sui Jingfeng
  2023-05-17 10:59 ` David Laight
  0 siblings, 1 reply; 17+ messages in thread
From: Sui Jingfeng @ 2023-05-16 17:30 UTC (permalink / raw)
  To: Sui Jingfeng, Li Yi
  Cc: Thomas Zimmermann, Maarten Lankhorst, Maxime Ripard, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel, loongson-kernel

From: Sui Jingfeng <suijingfeng@loongson.cn>

Both mode->crtc_htotal and mode->crtc_vtotal are u16 type,
mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type.
Using a u32 is enough to store the result, but considering that the
result will be casted to u64 soon after. We use a u64 type directly.
So there no need to cast it to signed type and cast back then.

Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: loongson-kernel@lists.loongnix.cn
---
 drivers/gpu/drm/drm_vblank.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 877e2067534f..d99c404b181b 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -622,7 +622,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 
 	/* Valid dotclock? */
 	if (dotclock > 0) {
-		int frame_size = mode->crtc_htotal * mode->crtc_vtotal;
+		u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal;
 
 		/*
 		 * Convert scanline length in pixels and video
@@ -630,7 +630,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 		 * in nanoseconds:
 		 */
 		linedur_ns  = div_u64((u64) mode->crtc_htotal * 1000000, dotclock);
-		framedur_ns = div_u64((u64) frame_size * 1000000, dotclock);
+		framedur_ns = div_u64(frame_size * 1000000, dotclock);
 
 		/*
 		 * Fields of interlaced scanout modes are only half a frame duration.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread
* [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast
@ 2023-05-16 16:59 Sui Jingfeng
  2023-05-16 17:06 ` Thomas Zimmermann
  0 siblings, 1 reply; 17+ messages in thread
From: Sui Jingfeng @ 2023-05-16 16:59 UTC (permalink / raw)
  To: suijingfeng
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, dri-devel, linux-kernel

Both mode->crtc_htotal and mode->crtc_vtotal are u16 type,
mode->crtc_htotal * mode->crtc_vtotal will results a unsigned type.
Using a u32 is enough to store the result, but considering that the
result will be casted to u64 soon after. We use a u64 type directly.

So there no need to cast it to signed type and cast back then.

Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/gpu/drm/drm_vblank.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
index 877e2067534f..d99c404b181b 100644
--- a/drivers/gpu/drm/drm_vblank.c
+++ b/drivers/gpu/drm/drm_vblank.c
@@ -622,7 +622,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 
 	/* Valid dotclock? */
 	if (dotclock > 0) {
-		int frame_size = mode->crtc_htotal * mode->crtc_vtotal;
+		u64 frame_size = mode->crtc_htotal * mode->crtc_vtotal;
 
 		/*
 		 * Convert scanline length in pixels and video
@@ -630,7 +630,7 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc,
 		 * in nanoseconds:
 		 */
 		linedur_ns  = div_u64((u64) mode->crtc_htotal * 1000000, dotclock);
-		framedur_ns = div_u64((u64) frame_size * 1000000, dotclock);
+		framedur_ns = div_u64(frame_size * 1000000, dotclock);
 
 		/*
 		 * Fields of interlaced scanout modes are only half a frame duration.
-- 
2.25.1


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

end of thread, other threads:[~2023-05-23  9:55 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-16 17:30 [PATCH] drm/drm_vblank.c: avoid unsigned int to signed int cast Sui Jingfeng
2023-05-17 10:59 ` David Laight
2023-05-17 18:08   ` Sui Jingfeng
2023-05-22 11:29     ` Jani Nikula
2023-05-22 11:55       ` Sui Jingfeng
2023-05-22 12:07         ` David Laight
2023-05-22 12:13         ` Jani Nikula
2023-05-22 12:53           ` Sui Jingfeng
2023-05-22 15:01             ` Jani Nikula
2023-05-23  3:55               ` Sui Jingfeng
2023-05-23  4:26       ` Sui Jingfeng
2023-05-23  8:12         ` Sui Jingfeng
2023-05-23  8:50         ` David Laight
2023-05-23  9:55           ` Sui Jingfeng
  -- strict thread matches above, loose matches on Subject: below --
2023-05-16 16:59 Sui Jingfeng
2023-05-16 17:06 ` Thomas Zimmermann
2023-05-16 17:13   ` Sui Jingfeng

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