drm/drm_vblank.c: avoid unsigned int to signed int cast

Message ID 20230516165931.2989639-1-suijingfeng@loongson.cn
State New
Headers
Series drm/drm_vblank.c: avoid unsigned int to signed int cast |

Commit Message

Sui Jingfeng May 16, 2023, 4:59 p.m. UTC
  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(-)
  

Comments

Thomas Zimmermann May 16, 2023, 5:06 p.m. UTC | #1
Am 16.05.23 um 18:59 schrieb Sui Jingfeng:
> 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

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>   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.

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
  
Sui Jingfeng May 16, 2023, 5:13 p.m. UTC | #2
Hi,

On 2023/5/17 01:06, Thomas Zimmermann wrote:
>
>
> Am 16.05.23 um 18:59 schrieb Sui Jingfeng:
>> 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
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>
Thanks a lot,  thanks for the response time also.

>> ---
>>   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.
>
  

Patch

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.