Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Mallesh Koujalagi <mallesh.koujalagi@intel.com>,
	intel-xe@lists.freedesktop.org, rodrigo.vivi@intel.com,
	matthew.brost@intel.com
Cc: anshuman.gupta@intel.com, badal.nilawar@intel.com,
	vinay.belgaumkar@intel.com, riana.tauro@intel.com,
	karthik.poosa@intel.com, sk.anirban@intel.com,
	raag.jadav@intel.com, aravind.iddamsetty@linux.intel.com,
	Mallesh Koujalagi <mallesh.koujalagi@intel.com>
Subject: Re: [PATCH] drm/xe/hwmon: Restrict LONG_MAX overflow check to 32-bit builds
Date: Fri, 23 Oct 2026 14:58:04 +0300	[thread overview]
Message-ID: <e5d55f7adef63e5ff054b1493f1759c83cf5e33b@intel.com> (raw)
In-Reply-To: <20261023082939.387258-2-mallesh.koujalagi@intel.com>

On Fri, 23 Oct 2026, Mallesh Koujalagi <mallesh.koujalagi@intel.com> wrote:
> The temperature decoding code stores the intermediate result in an
> s64 and checks it against LONG_MAX before assigning it to a long.
>
> This check is only needed on 32-bit architectures, where long is
> narrower than s64. On 64-bit systems, long and s64 are both 64 bits,
> so the condition can never be true.
>
> Wrap the check with BITS_PER_LONG == 32 so it is only compiled where
> it is needed, preserving the existing overflow protection on 32-bit
> architectures while eliminating the dead branch on 64-bit builds.

Why would it matter? Why make the code harder to read with the inline
#ifdef?

>
> Fixes: 24ec15d64617 ("drm/xe/hwmon: Decode CRI temperature registers as IEEE-754")
> Signed-off-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_hwmon.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index 42acfeb8818c..2ee51921acf5 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -1322,9 +1322,14 @@ static int xe_hwmon_temperature_decode(u32 reg_val, long *temperature)
>  		value = 0;
>  	}
>  
> -	/* Ensure the magnitude fits in long, which is 32-bit on some arches. */
> +#if BITS_PER_LONG == 32
> +	/*
> +	 * On 32-bit systems, long is smaller than s64, so the value may
> +	 * still overflow long even if it fits in s64.
> +	 */
>  	if (value > LONG_MAX)
>  		return -ERANGE;
> +#endif
>  
>  	if (reg_val & IEEE754_SIGN)
>  		value = -value;

-- 
Jani Nikula, Intel

  parent reply	other threads:[~2026-10-23 11:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-23  8:29 [PATCH] drm/xe/hwmon: Restrict LONG_MAX overflow check to 32-bit builds Mallesh Koujalagi
2026-10-23  8:37 ` ✓ CI.KUnit: success for " Patchwork
2026-10-23  9:24 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-23 11:20 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-10-23 11:58 ` Jani Nikula [this message]
2026-10-23 12:51   ` [PATCH] " Mallesh, Koujalagi
2026-10-23 13:01     ` Jani Nikula

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=e5d55f7adef63e5ff054b1493f1759c83cf5e33b@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=aravind.iddamsetty@linux.intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=mallesh.koujalagi@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=sk.anirban@intel.com \
    --cc=vinay.belgaumkar@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox