Re: [PATCH] sched.c

From: Andreas Dilger (adilger@clusterfs.com)
Date: Tue Aug 27 2002 - 19:41:54 EST


On Aug 28, 2002 02:13 +0200, Daniel Phillips wrote:
> On Tuesday 27 August 2002 20:35, Andrew Morton wrote:
> > Lahti Oy wrote:
> > > - for (i = 0; i < NR_CPUS; i++)
> > > + for (i = NR_CPUS; i; i--)
> > > sum += cpu_rq(i)->nr_running;
> >
> > Off-by-one there. You'd want
> >
> > for (i = NR_CPUS; --i >= 0; )
> >
> > or something similarly foul ;)
>
> int i = NR_CPUS;
>
> while (--i)

Actually, I prefer the following to avoid wrap-around conditions in
strange circumstances (i.e. if 'i' is manipulated between setting
and the while loop):

        while (i-- > 0) {
                ...
        }

Cheers, Andreas

--
Andreas Dilger
http://www-mddsp.enel.ucalgary.ca/People/adilger/
http://sourceforge.net/projects/ext2resize/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Aug 31 2002 - 22:00:21 EST