• V
    net: mscc: ocelot: avoid type promotion when calling ocelot_ifh_set_dest · 1f778d50
    Vladimir Oltean 提交于
    Smatch is confused by the fact that a 32-bit BIT(port) macro is passed
    as argument to the ocelot_ifh_set_dest function and warns:
    
    ocelot_xmit() warn: should '(((1))) << (dp->index)' be a 64 bit type?
    seville_xmit() warn: should '(((1))) << (dp->index)' be a 64 bit type?
    
    The destination port mask is copied into a 12-bit field of the packet,
    starting at bit offset 67 and ending at 56.
    
    So this DSA tagging protocol supports at most 12 bits, which is clearly
    less than 32. Attempting to send to a port number > 12 will cause the
    packing() call to truncate way before there will be 32-bit truncation
    due to type promotion of the BIT(port) argument towards u64.
    
    Therefore, smatch's fears that BIT(port) will do the wrong thing and
    cause unexpected truncation for "port" values >= 32 are unfounded.
    Nonetheless, let's silence the warning by explicitly passing an u64
    value to ocelot_ifh_set_dest, such that the compiler does not need to do
    a questionable type promotion.
    Reported-by: Nkernel test robot <lkp@intel.com>
    Reported-by: NDan Carpenter <dan.carpenter@oracle.com>
    Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: NDavid S. Miller <davem@davemloft.net>
    1f778d50
ocelot.c 56.0 KB