[PATCH 1/6] lib: include crc32.h conditionally on CONFIG_CRC32
David Laight
david.laight.linux at gmail.com
Mon May 4 05:43:18 PDT 2026
On Mon, 04 May 2026 10:03:10 +0200
"Arnd Bergmann" <arnd at arndb.de> wrote:
> On Thu, Apr 30, 2026, at 23:13, Yury Norov wrote:
> > Currently, bitreverse API is either declared based on
> > CONFIG_HAVE_ARCH_BITREVERSE, wired to arch implementation, or if the
> > arch has no bitreverse, based on generic implementation.
> >
> > So, regardless of CONFIG_BITREVERSE=n, the corresponding API is always
> > declared. If that happens, the functions become declared but not
> > implemented, which is an error.
>
> I'm not following that description. Why is it an error to declare
> a funtion that is not implemented? Isn't that how optional interfaces
> tend to work in general?
>
> > The only header requiring the crc32 and bitreverse prototypes is
> > include/linux/etherdevice.h. Thus, protect inclusion of corresponding
> > headers in the etherdevice with CONFIG_CRC32, together with the only
> > function depending on it.
> ...
> > #include <linux/if_ether.h>
> > #include <linux/netdevice.h>
> > #include <linux/random.h>
> > +#ifdef CONFIG_CRC32
> > #include <linux/crc32.h>
> > +#endif
> > #include <linux/unaligned.h>
> > #include <asm/bitsperlong.h>
>
> Don't add #ifdef blocks around headers. If the header cannot
> be included without side-effects, change the linux/crc32.h
> file instead of its users.
>
> It looks like the problem is the check for CONFIG_GENERIC_BITREVERSE
> in include/asm-generic/bitops/__bitrev.h, which ends up
> hinding the generic___bitrev32() helper without need.
>
> Simply removing the #ifdef there should avoid the build failure.
>
> > +#ifdef CONFIG_CRC32
> > /**
> > * eth_hw_addr_crc - Calculate CRC from netdev_hw_addr
> > * @ha: pointer to hardware address
> > @@ -291,6 +294,7 @@ static inline u32 eth_hw_addr_crc(struct netdev_hw_addr *ha)
> > {
> > return ether_crc(ETH_ALEN, ha->addr);
> > }
> > +#endif
>
> I see there are only user users of this function, neither of
> them are performance critical. So the other options would
> be to either open-code this function in the two callers
> and remove it entirely, or move it into net/ethernet/eth.c.
Or change to a #define so that only the users need to have the
required headers included.
But open-coding in the callers saves anyone trying to read the code
having to look at another file to see what is going on.
-- David
>
> Arnd
>
More information about the linux-riscv
mailing list