All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Golle" <daniel@makrotopia.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v6 06/13] drm/bridge: it6505: avoid division by zero in pixel clock calculation
Date: Sat, 25 Jul 2026 03:20:22 +0000	[thread overview]
Message-ID: <20260725032022.9C9E31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <a9664c9ddd026a22cd246c0aac878d3c0e204d50.1784947240.git.daniel@makrotopia.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] Unhandled hardware state when reading REG_AUDIO_INPUT_FREQ leads to division by zero and kernel panic.
- [Medium] Missing error handling for I2C reads leads to data corruption in video timing calculations.
- [Medium] Data race in `it6505_calc_video_info` corrupts pixel clock counter reading.
--

--- Patch [6]: [PATCH v6 06/13] drm/bridge: it6505: avoid division by zero in pixel clock calculation ---
commit 00522edef86150c061773cb0103cee92136a7a79
Author: Daniel Golle <daniel@makrotopia.org>
Subject: drm/bridge: it6505: avoid division by zero in pixel clock calculation

This commit fixes a potential division by zero in the pixel clock
computation. It moves the division of the counter sum to after the zero
check to avoid truncation of small values. This prevents sums of 1 or 2
from being evaluated as 0 and bypassing the check.

> diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
> index 3806b0b966376..b7eb746c8f8e5 100644
> --- a/drivers/gpu/drm/bridge/ite-it6505.c
> +++ b/drivers/gpu/drm/bridge/ite-it6505.c
> @@ -751,12 +751,13 @@ static void it6505_calc_video_info(struct it6505 *it6505)
>  		sum += rddata;

[Severity: Medium]
This is a pre-existing issue, but does this bitwise mask without checking for
negative error codes cause data corruption?

If I2C reads fail and return -ENODEV, the negative return value is
directly bitwise-masked and treated as a valid hardware reading.

For example, earlier in it6505_calc_video_info():

    htotal = it6505_read_word(it6505, REG_INPUT_HTOTAL) & 0x1FFF;

And similarly for the counter:

    rddata = it6505_read_word(it6505, REG_PCLK_COUNTER_VALUE) & 0xFFF;
    sum += rddata;

Could this lead to negative error codes being added to the counter sum,
corrupting the subsequent pixel clock math?

[Severity: Medium]
This isn't a bug introduced by this patch, but is there a data race in
it6505_calc_video_info() that corrupts the pixel clock counter reading?

This function performs a multi-step hardware sequence without holding any
locks:

    it6505_set_bits(it6505, REG_DATA_CTRL0, ENABLE_PCLK_COUNTER,
                    ENABLE_PCLK_COUNTER);
    usleep_range(10000, 15000);
    it6505_set_bits(it6505, REG_DATA_CTRL0, ENABLE_PCLK_COUNTER, 0x00);
    rddata = ...

Since this can be executed concurrently by the threaded IRQ handler
it6505_irq_scdt() and the debugfs read handler
receive_timing_debugfs_show(), could a debugfs read occurring during the IRQ
handling interleave register writes?

One thread might disable the counter prematurely while the other is sleeping,
resulting in an abnormally small reading.

Is this race condition the root cause of the division by zero that this patch
attempts to mitigate?

>  	}
>  
> +	sum /= 3;
> +
>  	if (sum == 0) {
>  		DRM_DEV_DEBUG_DRIVER(dev, "calc video timing error");
>  		return;
>  	}
>  
> -	sum /= 3;
>  	pclk = 13500 * 2048 / sum;
>  	it6505->video_info.clock = pclk;
>  	it6505->video_info.hdisplay = hdew;

[Severity: High]
This is a pre-existing issue not introduced by this patch, but can reading an
unhandled hardware state lead to a kernel panic?

Looking at it6505_enable_audio():

    regbe = it6505_read(it6505, REG_AUDIO_INPUT_FREQ);
    DRM_DEV_DEBUG_DRIVER(dev, "regbe:0x%02x audio input fs: %d.%d kHz",
                         regbe, 6750 / regbe, (6750 % regbe) * 10 / regbe);

If the hardware register contains 0, for instance if the audio clock is not
fully active or uninitialized, will the subsequent DRM_DEV_DEBUG_DRIVER macro
trigger a division by zero when evaluating 6750 / regbe?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784947240.git.daniel@makrotopia.org?part=6

  reply	other threads:[~2026-07-25  3:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25  2:57 [PATCH v6 00/13] drm/bridge: it6505: DP audio support + shared-DAI hw_params fix Daniel Golle
2026-07-25  2:58 ` [PATCH v6 01/13] drm/bridge: it6505: quiesce event sources and work on remove() Daniel Golle
2026-07-25  3:23   ` sashiko-bot
2026-07-25  2:58 ` [PATCH v6 02/13] drm/bridge: it6505: balance and disable runtime PM on remove Daniel Golle
2026-07-25  3:18   ` sashiko-bot
2026-07-25  2:58 ` [PATCH v6 03/13] drm/bridge: it6505: unregister DP AUX adapter on bridge detach Daniel Golle
2026-07-25  3:17   ` sashiko-bot
2026-07-25  2:58 ` [PATCH v6 04/13] drm/bridge: it6505: complete poweroff even if disabling regulators fails Daniel Golle
2026-07-25  3:17   ` sashiko-bot
2026-07-25  2:58 ` [PATCH v6 05/13] drm/bridge: it6505: bail out of the IRQ handler when status reads fail Daniel Golle
2026-07-25  2:59 ` [PATCH v6 06/13] drm/bridge: it6505: avoid division by zero in pixel clock calculation Daniel Golle
2026-07-25  3:20   ` sashiko-bot [this message]
2026-07-25  2:59 ` [PATCH v6 07/13] drm/bridge: it6505: avoid division by zero in audio FS debug print Daniel Golle
2026-07-25  3:16   ` sashiko-bot
2026-07-25  2:59 ` [PATCH v6 08/13] drm/bridge: it6505: guard against zero channel count in audio infoframe Daniel Golle
2026-07-25  3:00 ` [PATCH v6 09/13] drm/bridge: it6505: hold endpoint OF node reference while parsing it Daniel Golle
2026-07-25  3:15   ` sashiko-bot
2026-07-25  3:00 ` [PATCH v6 10/13] drm/bridge: it6505: reject a too short link-frequencies property Daniel Golle
2026-07-25  3:00 ` [PATCH v6 11/13] drm/bridge: it6505: don't write an error code back to the reset register Daniel Golle
2026-07-25  3:19   ` sashiko-bot
2026-07-25  3:01 ` [PATCH v6 12/13] drm/bridge: it6505: Add audio support Daniel Golle
2026-07-25  5:25   ` sashiko-bot
2026-07-25  3:01 ` [PATCH v6 13/13] drm/bridge: it6505: Don't reject audio hw_params without an encoder Daniel Golle

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=20260725032022.9C9E31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=daniel@makrotopia.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.