From: "Mallesh, Koujalagi" <mallesh.koujalagi@intel.com>
To: Jani Nikula <jani.nikula@linux.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>
Subject: Re: [PATCH] drm/xe/hwmon: Restrict LONG_MAX overflow check to 32-bit builds
Date: Fri, 23 Oct 2026 18:21:29 +0530 [thread overview]
Message-ID: <cf26d883-b8e4-441b-b739-40104b874b9b@intel.com> (raw)
In-Reply-To: <e5d55f7adef63e5ff054b1493f1759c83cf5e33b@intel.com>
On 23-10-2026 05:28 pm, Jani Nikula wrote:
> 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?
Static analysis tools complain that the code contains dead code on
64-bit systems because the "value > LONG_MAX" check is always false there.
My initial thought was to handle this explicitly for 32 bit systems,
but I agree that the #ifdef makes the code harder to read.
An alternative is to user overflows_type(), which handles both 32-bit and
64-bit cases without conditional code and keeps the overflow check clear
and simple.
Any thoughts? If that sounds reasonable, I'll send a next revision with
that approach.
Please let me know.
Thanks,
-/Mallesh
>> 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;
next prev parent reply other threads:[~2026-10-23 12:51 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 ` [PATCH] " Jani Nikula
2026-10-23 12:51 ` Mallesh, Koujalagi [this message]
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=cf26d883-b8e4-441b-b739-40104b874b9b@intel.com \
--to=mallesh.koujalagi@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=jani.nikula@linux.intel.com \
--cc=karthik.poosa@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