[PATCH] drm/xe: Fix coverity issue, truncation warning
Jani Nikula
jani.nikula at linux.intel.com
Tue Aug 5 08:01:18 UTC 2025
On Tue, 05 Aug 2025, "Gurram, Pravalika" <pravalika.gurram at intel.com> wrote:
>> -----Original Message-----
>> From: Brost, Matthew <matthew.brost at intel.com>
>> Sent: Tuesday, August 5, 2025 9:05 AM
>> To: Gurram, Pravalika <pravalika.gurram at intel.com>
>> Cc: intel-xe at lists.freedesktop.org; Wajdeczko, Michal
>> <Michal.Wajdeczko at intel.com>
>> Subject: Re: [PATCH] drm/xe: Fix coverity issue, truncation warning
>>
>> On Mon, Aug 04, 2025 at 04:14:09PM +0530, Pravalika Gurram wrote:
>> > Use conditional assignment to avoid cast truncation warning.
>> > Set instance to 0 when hw_reports_to_instance_zero() returns false.
>> >
>> > Fixes: 95336cfd5b2ce ("drm/xe: Add memirq report page address
>> > helpers")
>>
>> Definitiely no fixes tag required here.
>>
>> >
>> > Signed-off-by: Pravalika Gurram <pravalika.gurram at intel.com>
>> > ---
>> > drivers/gpu/drm/xe/xe_memirq.c | 3 ++-
>> > 1 file changed, 2 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/drivers/gpu/drm/xe/xe_memirq.c
>> > b/drivers/gpu/drm/xe/xe_memirq.c index 49c45ec3e83c..75ddf4eda355
>> > 100644
>> > --- a/drivers/gpu/drm/xe/xe_memirq.c
>> > +++ b/drivers/gpu/drm/xe/xe_memirq.c
>> > @@ -257,7 +257,8 @@ static u32 __memirq_source_page(struct xe_memirq
>> *memirq, u16 instance)
>> > memirq_assert(memirq, instance <= XE_HW_ENGINE_MAX_INSTANCE);
>> > memirq_assert(memirq, memirq->bo);
>> >
>> > - instance = hw_reports_to_instance_zero(memirq) ? instance : 0;
>> > + if (!hw_reports_to_instance_zero(memirq))
>> > + instance = 0;
>>
>> I'm failing to see how this fixes any possible static checker. Could you explain?
>>
>> That said, I do prefer the way you have changed it here.
>>
>> Matt
>>
>>
> The Static analyzer treating the ternary expression "hw_reports_to_instance_zero(memirq) ? instance : 0" evaluates to a 32-bit value
> Hence, I have added if condition to avoid a static checker error
> cast overflow: Truncation due to cast operation on hw_reports_to_instance_zero(memirq) ? instance : 0 from 32 to 16 bits.
Obviously it's not possible for this expression to truncate anything,
and the static analyzer is being silly.
BR,
Jani.
>
> Pravalika
>
>> > return xe_bo_ggtt_addr(memirq->bo) +
>> > XE_MEMIRQ_SOURCE_OFFSET(instance);
>> > }
>> >
>> > --
>> > 2.34.1
>> >
--
Jani Nikula, Intel
More information about the Intel-xe
mailing list