lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <063D6719AE5E284EB5DD2968C1650D6D0F6CBE9F@AcuExch.aculab.com>
Date:	Wed, 26 Feb 2014 17:05:41 +0000
From:	David Laight <David.Laight@...LAB.COM>
To:	'Alexander Aring' <alex.aring@...il.com>
CC:	"alex.bluesman.smirnov@...il.com" <alex.bluesman.smirnov@...il.com>,
	"dbaryshkov@...il.com" <dbaryshkov@...il.com>,
	"davem@...emloft.net" <davem@...emloft.net>,
	"linux-zigbee-devel@...ts.sourceforge.net" 
	<linux-zigbee-devel@...ts.sourceforge.net>,
	"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
	"martin.townsend@...lon.com" <martin.townsend@...lon.com>
Subject: RE: [PATCH net-next v4 2/8] 6lowpan: add uncompress header size
 function

From: Alexander Aring 
> On Wed, Feb 26, 2014 at 04:10:05PM +0000, David Laight wrote:
> > From: Alexander Aring
...
> > > +static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
> > > +{
> > > +	switch (addr_mode) {
> > > +	case LOWPAN_IPHC_ADDR_00:
> > > +		return 16;
> > > +	case LOWPAN_IPHC_ADDR_01:
> > > +		return 8;
> > > +	case LOWPAN_IPHC_ADDR_02:
> > > +		return 2;
> > > +	default:
> > > +		return 0;
> > > +	}
> > > +}
> >
> > The compiler will generate much better code if you index an array instead
> > of using a switch statement.
> >
> >
> 
> You mean something like:
> 
> static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
> {
>         const u8 res[] = { 16, 8, 2, 0 };
>         return res[addr_mode];
> }
> 
> or should I drop the array from the stack and declare it static?

You definitely want the array to be static (as well as const).
You could also use named initialisers.
If I've got the syntax right that would be:

		static const u8 sizes[] = {
			[LOWPAN_IPHC_ADDR_00] = 16,
			[LOWPAN_IPHC_ADDR_01] = 8,
			[LOWPAN_IPHC_ADDR_02] = 2,
		};
		return sizes[addr_mode];

Whether you need a bound check (or the 4th array index) depends on where
the input value comes from.

	David

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ