• Alexey Dobriyan's avatar
    netns: make struct pernet_operations::id unsigned int · c7d03a00
    Alexey Dobriyan authored
    Make struct pernet_operations::id unsigned.
    
    There are 2 reasons to do so:
    
    1)
    This field is really an index into an zero based array and
    thus is unsigned entity. Using negative value is out-of-bound
    access by definition.
    
    2)
    On x86_64 unsigned 32-bit data which are mixed with pointers
    via array indexing or offsets added or subtracted to pointers
    are preffered to signed 32-bit data.
    
    "int" being used as an array index needs to be sign-extended
    to 64-bit before being used.
    
    	void f(long *p, int i)
    	{
    		g(p[i]);
    	}
    
      roughly translates to
    
    	movsx	rsi, esi
    	mov	rdi, [rsi+...]
    	call 	g
    
    MOVSX is 3 byte instruction which isn't necessary if the variable is
    unsigned because x86_64 is zero extending by default.
    
    Now, there is net_generic() function which, you guessed it right, uses
    "int" as an array index:
    
    	static inline void *net_generic(const struct net *net, int id)
    	{
    		...
    		ptr = ng->ptr[id - 1];
    		...
    	}
    
    And this function is used a lot, so those sign...
    c7d03a00
ip_vti.c 15.4 KB