[Intel-gfx] [PATCH] drm/i915/tv: avoid possible division by zero
Su Hui
suhui at nfschina.com
Tue Jul 18 01:13:11 UTC 2023
On 2023/7/17 22:52, Andrzej Hajda wrote:
>
>
> On 17.07.2023 08:22, Su Hui wrote:
>> Clang warning: drivers/gpu/drm/i915/display/intel_tv.c:
>> line 991, column 22 Division by zero.
>> Assuming tv_mode->oversample=1 and (!tv_mode->progressive)=1,
>> then division by zero will happen.
>>
>> Fixes: 1bba5543e4fe ("drm/i915: Fix TV encoder clock computation")
>> Signed-off-by: Su Hui <suhui at nfschina.com>
>> ---
>> drivers/gpu/drm/i915/display/intel_tv.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/i915/display/intel_tv.c
>> b/drivers/gpu/drm/i915/display/intel_tv.c
>> index 36b479b46b60..82b54af51f23 100644
>> --- a/drivers/gpu/drm/i915/display/intel_tv.c
>> +++ b/drivers/gpu/drm/i915/display/intel_tv.c
>> @@ -988,7 +988,8 @@ intel_tv_mode_to_mode(struct drm_display_mode *mode,
>> const struct tv_mode *tv_mode,
>> int clock)
>> {
>> - mode->clock = clock / (tv_mode->oversample >>
>> !tv_mode->progressive);
>> + mode->clock = clock / (tv_mode->oversample != 1 ?
>> + tv_mode->oversample >> !tv_mode->progressive : 1);
>
> Seems too smart to me, why not just:
> mode->clock = clock / tv_mode->oversample;
> if (!tv_mode->progressive)
> mode->clock <<= 1;
> Or trying being smart:
> mode->clock = clock / tv_mode->oversample << !tv_mode->progressive;
Hi,
Yes, this is more readable and clear.
Thanks four your advice. I will send v2 soon.
Su Hui
>
> Btw in both cases there is assumption tv_mode->oversample != 0, I
> guess it is true.
>
> Regards
> Andrzej
>
>> /*
>> * tv_mode horizontal timings:
>
More information about the Intel-gfx
mailing list