All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Krzysztof Karas <krzysztof.karas@intel.com>
Cc: intel-gfx@lists.freedesktop.org,
	Andi Shyti <andi.shyti@linux.intel.com>,
	Sebastian Brzezinka <sebastian.brzezinka@intel.com>,
	Krzysztof Niemiec <krzysztof.niemiec@intel.com>,
	Jani Nikula <jani.nikula@linux.intel.com>
Subject: Re: [PATCH v5 3/3] drm: Avoid undefined behavior on u16 multiplication in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
Date: Mon, 8 Dec 2025 19:15:42 +0200	[thread overview]
Message-ID: <aTcHvk1QhPNfKT89@intel.com> (raw)
In-Reply-To: <20251204143827.111428-4-krzysztof.karas@intel.com>

On Thu, Dec 04, 2025 at 02:38:27PM +0000, Krzysztof Karas wrote:
> vpos (int) field multiplied by crtc_htotal (u16) may cause
> implicit promotion of the latter and overflow the result causing
> undefined behavior.

How is that undefined?

> 
> Cast the u16 operand to (s32) type to avoid that.
> 
> Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
> ---
> 
> v4:
> * use s32 cast instead of int;
> 
>  drivers/gpu/drm/drm_vblank.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c
> index 32d013c5c8fc..e25dcaa6cad4 100644
> --- a/drivers/gpu/drm/drm_vblank.c
> +++ b/drivers/gpu/drm/drm_vblank.c
> @@ -791,7 +791,7 @@ drm_crtc_vblank_helper_get_vblank_timestamp_internal(
>  	 * since start of scanout at first display scanline. delta_ns
>  	 * can be negative if start of scanout hasn't happened yet.
>  	 */
> -	delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos),
> +	delta_ns = div_s64(1000000LL * (vpos * (s32)mode->crtc_htotal + hpos),
>  			   mode->crtc_clock);
>  
>  	/* Subtract time delta from raw timestamp to get final
> -- 
> 2.34.1

-- 
Ville Syrjälä
Intel

  parent reply	other threads:[~2025-12-08 17:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-04 14:38 [PATCH v5 0/3] drm: Miscellaneous fixes in drm code Krzysztof Karas
2025-12-04 14:38 ` [PATCH v5 1/3] drm: Warn and return before division by 0 Krzysztof Karas
2025-12-05 15:31   ` Krzysztof Niemiec
2025-12-16 14:12   ` Andi Shyti
2025-12-04 14:38 ` [PATCH v5 2/3] drm: Avoid suspicious operations in drm_fb_dma_get_gem_addr() Krzysztof Karas
2025-12-05 15:32   ` Krzysztof Niemiec
2025-12-16 14:11   ` Andi Shyti
2025-12-04 14:38 ` [PATCH v5 3/3] drm: Avoid undefined behavior on u16 multiplication in drm_crtc_vblank_helper_get_vblank_timestamp_internal() Krzysztof Karas
2025-12-05 15:32   ` Krzysztof Niemiec
2025-12-08 17:15   ` Ville Syrjälä [this message]
2025-12-09  7:47     ` Krzysztof Karas
2025-12-09  8:00       ` Ville Syrjälä
2025-12-05  8:50 ` ✓ i915.CI.BAT: success for drm: Miscellaneous fixes in drm code (rev5) Patchwork
2025-12-06  4:39 ` ✗ i915.CI.Full: failure " 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=aTcHvk1QhPNfKT89@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=andi.shyti@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=krzysztof.karas@intel.com \
    --cc=krzysztof.niemiec@intel.com \
    --cc=sebastian.brzezinka@intel.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 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.