Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mv643xx_eth: Neaten mv643xx_eth_program_multicast_filter

The code around the allocation and loops are a bit obfuscated.

Neaten it by using:

o kcalloc with decimal count and sizeof(u32)
o Decimal loop indexing and i++ not i += 4
o A promiscuous block using a similar style
to the multicast block
o Remove unnecessary variables

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Joe Perches and committed by
David S. Miller
8b711d6d 29feb66a

+22 -21
+22 -21
drivers/net/ethernet/marvell/mv643xx_eth.c
··· 1845 1845 struct netdev_hw_addr *ha; 1846 1846 int i; 1847 1847 1848 - if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { 1849 - int port_num; 1850 - u32 accept; 1848 + if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) 1849 + goto promiscuous; 1851 1850 1852 - oom: 1853 - port_num = mp->port_num; 1854 - accept = 0x01010101; 1855 - for (i = 0; i < 0x100; i += 4) { 1856 - wrl(mp, SPECIAL_MCAST_TABLE(port_num) + i, accept); 1857 - wrl(mp, OTHER_MCAST_TABLE(port_num) + i, accept); 1858 - } 1859 - return; 1860 - } 1861 - 1862 - mc_spec = kzalloc(0x200, GFP_ATOMIC); 1863 - if (mc_spec == NULL) 1864 - goto oom; 1865 - mc_other = mc_spec + (0x100 >> 2); 1851 + /* Allocate both mc_spec and mc_other tables */ 1852 + mc_spec = kcalloc(128, sizeof(u32), GFP_ATOMIC); 1853 + if (!mc_spec) 1854 + goto promiscuous; 1855 + mc_other = &mc_spec[64]; 1866 1856 1867 1857 netdev_for_each_mc_addr(ha, dev) { 1868 1858 u8 *a = ha->addr; 1869 1859 u32 *table; 1870 - int entry; 1860 + u8 entry; 1871 1861 1872 1862 if (memcmp(a, "\x01\x00\x5e\x00\x00", 5) == 0) { 1873 1863 table = mc_spec; ··· 1870 1880 table[entry >> 2] |= 1 << (8 * (entry & 3)); 1871 1881 } 1872 1882 1873 - for (i = 0; i < 0x100; i += 4) { 1874 - wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i, mc_spec[i >> 2]); 1875 - wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i, mc_other[i >> 2]); 1883 + for (i = 0; i < 64; i++) { 1884 + wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32), 1885 + mc_spec[i]); 1886 + wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32), 1887 + mc_other[i]); 1876 1888 } 1877 1889 1878 1890 kfree(mc_spec); 1891 + return; 1892 + 1893 + promiscuous: 1894 + for (i = 0; i < 64; i++) { 1895 + wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32), 1896 + 0x01010101u); 1897 + wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32), 1898 + 0x01010101u); 1899 + } 1879 1900 } 1880 1901 1881 1902 static void mv643xx_eth_set_rx_mode(struct net_device *dev)