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

Configure Feed

Select the types of activity you want to include in your feed.

net: apple: bmac: use crc32() instead of hand-rolled equivalent

The calculation done by bmac_crc(addr) followed by taking the low 6 bits
and reversing them is equivalent to taking the high 6 bits from
crc32(~0, addr, ETH_ALEN). Just do that instead.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Link: https://patch.msgid.link/20250513050142.635391-1-ebiggers@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Biggers and committed by
Jakub Kicinski
a1dc1dee 88906f55

+2 -58
+2 -58
drivers/net/ethernet/apple/bmac.c
··· 20 20 #include <linux/init.h> 21 21 #include <linux/spinlock.h> 22 22 #include <linux/crc32.h> 23 - #include <linux/crc32poly.h> 24 23 #include <linux/bitrev.h> 25 24 #include <linux/ethtool.h> 26 25 #include <linux/slab.h> ··· 795 796 } 796 797 797 798 #ifndef SUNHME_MULTICAST 798 - /* Real fast bit-reversal algorithm, 6-bit values */ 799 - static int reverse6[64] = { 800 - 0x0,0x20,0x10,0x30,0x8,0x28,0x18,0x38, 801 - 0x4,0x24,0x14,0x34,0xc,0x2c,0x1c,0x3c, 802 - 0x2,0x22,0x12,0x32,0xa,0x2a,0x1a,0x3a, 803 - 0x6,0x26,0x16,0x36,0xe,0x2e,0x1e,0x3e, 804 - 0x1,0x21,0x11,0x31,0x9,0x29,0x19,0x39, 805 - 0x5,0x25,0x15,0x35,0xd,0x2d,0x1d,0x3d, 806 - 0x3,0x23,0x13,0x33,0xb,0x2b,0x1b,0x3b, 807 - 0x7,0x27,0x17,0x37,0xf,0x2f,0x1f,0x3f 808 - }; 809 - 810 - static unsigned int 811 - crc416(unsigned int curval, unsigned short nxtval) 812 - { 813 - unsigned int counter, cur = curval, next = nxtval; 814 - int high_crc_set, low_data_set; 815 - 816 - /* Swap bytes */ 817 - next = ((next & 0x00FF) << 8) | (next >> 8); 818 - 819 - /* Compute bit-by-bit */ 820 - for (counter = 0; counter < 16; ++counter) { 821 - /* is high CRC bit set? */ 822 - if ((cur & 0x80000000) == 0) high_crc_set = 0; 823 - else high_crc_set = 1; 824 - 825 - cur = cur << 1; 826 - 827 - if ((next & 0x0001) == 0) low_data_set = 0; 828 - else low_data_set = 1; 829 - 830 - next = next >> 1; 831 - 832 - /* do the XOR */ 833 - if (high_crc_set ^ low_data_set) cur = cur ^ CRC32_POLY_BE; 834 - } 835 - return cur; 836 - } 837 - 838 - static unsigned int 839 - bmac_crc(unsigned short *address) 840 - { 841 - unsigned int newcrc; 842 - 843 - XXDEBUG(("bmac_crc: addr=%#04x, %#04x, %#04x\n", *address, address[1], address[2])); 844 - newcrc = crc416(0xffffffff, *address); /* address bits 47 - 32 */ 845 - newcrc = crc416(newcrc, address[1]); /* address bits 31 - 16 */ 846 - newcrc = crc416(newcrc, address[2]); /* address bits 15 - 0 */ 847 - 848 - return(newcrc); 849 - } 850 - 851 799 /* 852 800 * Add requested mcast addr to BMac's hash table filter. 853 801 * ··· 807 861 unsigned short mask; 808 862 809 863 if (!(*addr)) return; 810 - crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */ 811 - crc = reverse6[crc]; /* Hyperfast bit-reversing algorithm */ 864 + crc = crc32(~0, addr, ETH_ALEN) >> 26; 812 865 if (bp->hash_use_count[crc]++) return; /* This bit is already set */ 813 866 mask = crc % 16; 814 867 mask = (unsigned char)1 << mask; ··· 821 876 unsigned char mask; 822 877 823 878 /* Now, delete the address from the filter copy, as indicated */ 824 - crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */ 825 - crc = reverse6[crc]; /* Hyperfast bit-reversing algorithm */ 879 + crc = crc32(~0, addr, ETH_ALEN) >> 26; 826 880 if (bp->hash_use_count[crc] == 0) return; /* That bit wasn't in use! */ 827 881 if (--bp->hash_use_count[crc]) return; /* That bit is still in use */ 828 882 mask = crc % 16;