[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6DCFFE86D8@AcuExch.aculab.com>
Date: Wed, 10 May 2017 11:12:10 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Alexei Starovoitov' <alexei.starovoitov@...il.com>,
David Miller <davem@...emloft.net>
CC: "daniel@...earbox.net" <daniel@...earbox.net>,
"ast@...com" <ast@...com>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: bpf pointer alignment validation
From: Alexei Starovoitov
> Sent: 10 May 2017 06:58
> > +static u32 calc_align(u32 imm)
> > +{
> > + u32 align = 1;
> > +
> > + if (!imm)
> > + return 1U << 31;
> > +
> > + while (!(imm & 1)) {
> > + imm >>= 1;
> > + align <<= 1;
> > + }
> > + return align;
> > +}
>
> same question as in previous reply.
> Why not to use something like:
> static u32 calc_align(u32 n)
> {
> if (!n)
> return 1U << 31;
> return n - ((n - 1) & n);
> }
That function needs a comment saying what it returns.
Think I'd write it as:
return n & ~(n & (n - 1));
(even though that might be one more instruction)
David
Powered by blists - more mailing lists