[igt-dev] [PATCH i-g-t v8 1/6] lib/drmtest: allow out of order device opening

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu Oct 5 12:03:57 UTC 2023


On Thu, Oct 05, 2023 at 01:44:17PM +0200, Zbigniew Kempczyński wrote:

<cut>
> > diff --git a/lib/drmtest.c b/lib/drmtest.c
> > index e1da66c87..43524c5ad 100644
> > --- a/lib/drmtest.c
> > +++ b/lib/drmtest.c
> > @@ -296,13 +296,18 @@ static int _opened_fds_count;
> >  static void _set_opened_fd(int idx, int fd)
> >  {
> >  	assert(idx < ARRAY_SIZE(_opened_fds));
> > -	assert(idx <= _opened_fds_count);
> > +
> > +	if (idx >= _opened_fds_count) {
> > +		for (int i = _opened_fds_count; i < idx; ++i)
> > +			_opened_fds[i].fd = -1;
> > +	}
> 
> Do you need if conditional? I mean if idx == _opened_fds_count
> (let's say _opened _fds_count == 5 and idx == 5, so you're hiting
> next element) and for loop just won't run -> i = 5, i < 5.
> 
> >  
> >  	_opened_fds[idx].fd = fd;
> 
> And you're write fd at index 5.
> 
> >  
> >  	assert(fstat(fd, &_opened_fds[idx].stat) == 0);
> >  
> > -	_opened_fds_count = idx+1;
> > +	if (idx >= _opened_fds_count)
> > +		_opened_fds_count = idx + 1;
> >  }
> 
> Anyway, you're allowing to selectively extend currently opened
> fd array keeping -1 on not occupied slots.
> 
> Rest looks good to me.
> 

I've forgotten to write about r-b - after addressing above conditional
nitpick.

> Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
> --
> Zbigniew

--
Zbigniew


More information about the igt-dev mailing list