From: "Poosa, Karthik" <karthik.poosa@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>,
<sk.anirban@intel.com>, <raag.jadav@intel.com>,
<aravind.iddamsetty@linux.intel.com>,
<jani.nikula@linux.intel.com>
Subject: Re: [PATCH v2] drm/xe/hwmon: Use overflows_type() for temperature range check
Date: Wed, 28 Oct 2026 10:56:11 +0530 [thread overview]
Message-ID: <e93b9746-d716-414b-9eda-ee19ea8cfdec@intel.com> (raw)
In-Reply-To: <c8a8e54a-df3f-43cc-a5b5-ec67597898c5@intel.com>
On 26-10-2026 18:06, Mallesh, Koujalagi wrote:
>
> On 26-10-2026 05:04 pm, Poosa, Karthik wrote:
>>
>> On 23-10-2026 20:06, Mallesh Koujalagi wrote:
>>> The temperature value is calculated as an s64 before being stored
>>> in a long. Check whether the value fits in the target type using
>>> overflows_type() instead of comparing against LONG_MAX directly.
>>>
>>> This keeps the overflow check correct on both 32-bit and 64-bit
>>> systems and avoids architecture-specific handling.
>>>
>>> Fixes: 24ec15d64617 ("drm/xe/hwmon: Decode CRI temperature registers
>>> as IEEE-754")
>>> Signed-off-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
>>> ---
>>> v2:
>>> - Use overflows_type(), instead of #ifdef. (Jani)
>>> ---
>>> drivers/gpu/drm/xe/xe_hwmon.c | 5 +++--
>>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c
>>> b/drivers/gpu/drm/xe/xe_hwmon.c
>>> index 42acfeb8818c..515b288f18e5 100644
>>> --- a/drivers/gpu/drm/xe/xe_hwmon.c
>>> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
>>> @@ -6,6 +6,7 @@
>>> #include <linux/hwmon-sysfs.h>
>>> #include <linux/hwmon.h>
>>> #include <linux/jiffies.h>
>>> +#include <linux/overflow.h>
>>> #include <linux/types.h>
>>> #include <linux/units.h>
>>> @@ -1322,8 +1323,8 @@ 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 (value > LONG_MAX)
>>> + /* Ensure the decoded value fits in a long. */
>>> + if (overflows_type(value, *temperature))
>> Is this change addressing an issue reported by a static analysis tool ?
> Yes, it's reported by a static analysis tool.
>>
>> |LONG_MAX| already reflects the platform-specific size of |long|, so
>> is this still needed ?
>>
> On 64 bit arch, where long and s64 are the same width, however (value
> > LONG_MAX)
>
> is always false because LONG_MAX is 9223372036854775807LL /*
> (long)(~0UL >> 1) */,
>
> As a result, "return -ERANGE" path is considered dead code and gets
> flagged.
>
>
> Using overflows_type() makes the overflow check explicit across 32-bit
> and 64-bit arch and avoid flagging by
>
> static analysis tool without changing the behavior.
>
>
> Thanks,
>
> -/Mallesh
okay,
Reviewed-by: Karthik Poosa <karthik.poosa@intel.com>
>
>>> return -ERANGE;
>>> if (reg_val & IEEE754_SIGN)
next prev parent reply other threads:[~2026-10-28 5:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 14:36 [PATCH v2] drm/xe/hwmon: Use overflows_type() for temperature range check Mallesh Koujalagi
2026-10-23 14:45 ` ✓ CI.KUnit: success for " Patchwork
2026-10-23 15:26 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-23 21:40 ` ✓ Xe.CI.FULL: " Patchwork
2026-10-26 11:34 ` [PATCH v2] " Poosa, Karthik
2026-10-26 12:36 ` Mallesh, Koujalagi
2026-10-28 5:26 ` Poosa, Karthik [this message]
2026-10-27 16:08 ` 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=e93b9746-d716-414b-9eda-ee19ea8cfdec@intel.com \
--to=karthik.poosa@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=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