Moving ethernet VLAN tags into the mbuf packet header (from mtags)

Chuck Swiger cswiger at mac.com
Tue Sep 12 09:42:34 PDT 2006


On Sep 12, 2006, at 5:56 AM, Andre Oppermann wrote:
>> Now I can't but do some nitpicking :-)  In if_vlan.c, the "inenc"
>> variable is set to 0 or 1 depending on the branch taken in the
>> if-else clause.  Then why to initialize it at its definition?  I
>> think that the better style would be:
>> 	int inenc;
>> 	if (m->m_flags & M_VLAN) {
>> 		...
>> 		inenc = 0;
>> 	} else {
>> 		...
>> 		inenc = 1;
>> 	}
>> AFAIK, C compilers are clever enough to avoid false "uninitialized
>> variable" warning for the code.
>
> Good point.  This can certainly be improved.  For the first patch
> I tried to be as mechanical as I could be.

So long as there does not exist another code path (via break,  
continue, goto, etc) which can avoid passing one statement or the  
other-- and so long as nobody later on adds code which changes the  
underlying assumption.

In terms of efficiency, zero'ing a bunch of automatic variables which  
get put on the stack during function entry is usually cheaper to do  
than doing conditional initialization later on in the code.  It  
depends on the underlying CPU architecture, but many have an  
instruction which can perform a bzero() or memset() rapidly.

-- 
-Chuck



More information about the freebsd-net mailing list