Subject: Re: [PATCH net-next 03/10] net/mlx5: hw counters: Replace IDR+lists with xarray

From: Simon Horman <[email-masked]>
Date: Tue, 27 Aug 2024 16:20:41 +0100

On Tue, Aug 27, 2024 at 04:01:30PM +0100, Simon Horman wrote:
> + Dan
> 
> On Tue, Aug 27, 2024 at 11:14:10AM +0000, Cosmin Ratiu wrote:
> > On Thu, 2024-08-15 at 14:44 +0100, Simon Horman wrote:
> > > On Thu, Aug 15, 2024 at 08:46:49AM +0300, Tariq Toukan wrote:
> > [...]
> > > > +	u32 last_bulk_id = 0;
> > > > +	u64 bulk_query_time;
> > > >  	u32 bulk_base_id;
> > [...]
> > > > +	xas_for_each(&xas, counter, U32_MAX) {
> > [...]
> > > > +		if (unlikely(counter->id >= last_bulk_id)) {
> > > > +			/* Start new bulk query. */
> > > > +			/* First id must be aligned to 4 when using bulk query. */
> > > > +			bulk_base_id = counter->id & ~0x3;
> > [...]
> > > > +			bulk_query_time = jiffies;
> > [...]
> > > >  		}
> > > 
> > > Hi Cosmin and Tariq,
> > > 
> > > It looks like bulk_query_time and bulk_base_id may be uninitialised or
> > > stale - from a previous loop iteration - if the condition above is not met.
> > > 
> > > Flagged by Smatch.
> > 
> > I believe this is a false positive. I snipped parts from the reply
> > above to focus on the relevant parts:
> > - last_bulk_id always starts at 0 so
> > - the if branch will always be executed in the first iteration and
> > - it will set bulk_query_time and bulk_base_id for future iterations.
> 
> Thanks,
> 
> I will look over this a second time with that in mind, my base assumption
> being that you are correct.

Thanks,

as both counter->id and last_bulk_id are unsigned I agree with your
analysis above, and that this is a false positive.

I don't think any further action is required at this time.
Sorry for the noise.

> 
> > I am not familiar with Smatch, is there a way to convince it to
> > interpret the code correctly (some annotations perhaps)?
> > The alternatives are to accept the false positive or explicitly
> > initialize those vars to something, which is suboptimal and would be
> > working around a tooling failure.
> 
> I think that if it is a false positive it can simply be ignored.
> I CCed Dan in case he has any feedback on that.
> 
>