Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Hajda <andrzej.hajda@intel.com>
To: Su Hui <suhui@nfschina.com>, Dan Carpenter <dan.carpenter@linaro.org>
Cc: kernel-janitors@vger.kernel.org, llvm@lists.linux.dev,
	dri-devel@lists.freedesktop.org, trix@redhat.com,
	intel-gfx@lists.freedesktop.org, ndesaulniers@google.com,
	linux-kernel@vger.kernel.org, nathan@kernel.org,
	mripard@kernel.org, daniel@ffwll.ch, rodrigo.vivi@intel.com,
	airlied@gmail.com
Subject: Re: [Intel-gfx] [PATCH] drm/i915/tv: avoid possible division by zero
Date: Tue, 18 Jul 2023 13:28:38 +0200	[thread overview]
Message-ID: <3c7dfc18-539f-2b0c-0c77-48b89ef96560@intel.com> (raw)
In-Reply-To: <8e3e945b-9cae-71e9-fc68-dc1c64e5ea86@nfschina.com>



On 18.07.2023 12:10, Su Hui wrote:
> On 2023/7/18 13:39, Dan Carpenter wrote:
>> On Mon, Jul 17, 2023 at 04:52:51PM +0200, 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@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;
>> This is nice.
>
> mode->clock = clock / tv_mode->oversample << !tv_mode->progressive;
>
> But I think this one is much better,  it has less code and run faster.
> Should I resend v3 to add some explanation or follow Dan's advice?

Speed gain here is irrelevant here, and disputable.

One thing which could be problematic is that we could loose the least 
significant bit in mode->clock,
in case non-progressive, but I am not sure if it really matters, as 
mode->clock is not precise value anyway.
Alternatively we could 1st shift, then divide, but in this case overflow 
can occur, at least in theory - I suspect there are no such big clocks 
(in kHz).

Finally I would agree with Dan, readability is better with conditional.

Regards
Andrzej

>
> Su Hui
>
>> regards,
>> dan carpenter


  reply	other threads:[~2023-07-18 11:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-17  6:22 [Intel-gfx] [PATCH] drm/i915/tv: avoid possible division by zero Su Hui
2023-07-17 14:52 ` Andrzej Hajda
2023-07-18  1:13   ` Su Hui
2023-07-18  5:39   ` Dan Carpenter
2023-07-18 10:10     ` Su Hui
2023-07-18 11:28       ` Andrzej Hajda [this message]
2023-07-19  2:12         ` Su Hui
2023-07-17 18:24 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2023-07-17 22:51 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3c7dfc18-539f-2b0c-0c77-48b89ef96560@intel.com \
    --to=andrzej.hajda@intel.com \
    --cc=airlied@gmail.com \
    --cc=dan.carpenter@linaro.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mripard@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=suhui@nfschina.com \
    --cc=trix@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox