Skip to content

Commit 8b711d6

Browse files
JoePerchesdavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 29feb66 commit 8b711d6

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

drivers/net/ethernet/marvell/mv643xx_eth.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,29 +1845,19 @@ static void mv643xx_eth_program_multicast_filter(struct net_device *dev)
18451845
struct netdev_hw_addr *ha;
18461846
int i;
18471847

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;
18511850

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];
18661856

18671857
netdev_for_each_mc_addr(ha, dev) {
18681858
u8 *a = ha->addr;
18691859
u32 *table;
1870-
int entry;
1860+
u8 entry;
18711861

18721862
if (memcmp(a, "\x01\x00\x5e\x00\x00", 5) == 0) {
18731863
table = mc_spec;
@@ -1880,12 +1870,23 @@ static void mv643xx_eth_program_multicast_filter(struct net_device *dev)
18801870
table[entry >> 2] |= 1 << (8 * (entry & 3));
18811871
}
18821872

1883-
for (i = 0; i < 0x100; i += 4) {
1884-
wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i, mc_spec[i >> 2]);
1885-
wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i, mc_other[i >> 2]);
1873+
for (i = 0; i < 64; i++) {
1874+
wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
1875+
mc_spec[i]);
1876+
wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
1877+
mc_other[i]);
18861878
}
18871879

18881880
kfree(mc_spec);
1881+
return;
1882+
1883+
promiscuous:
1884+
for (i = 0; i < 64; i++) {
1885+
wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
1886+
0x01010101u);
1887+
wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i * sizeof(u32),
1888+
0x01010101u);
1889+
}
18891890
}
18901891

18911892
static void mv643xx_eth_set_rx_mode(struct net_device *dev)

0 commit comments

Comments
 (0)