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.

lib/crc32: make crc32c() go directly to lib

Now that the lower level __crc32c_le() library function is optimized for
each architecture, make crc32c() just call that instead of taking an
inefficient and error-prone detour through the shash API.

Note: a future cleanup should make crc32c_le() be the actual library
function instead of __crc32c_le(). That will require updating callers
of __crc32c_le() to use crc32c_le() instead, and updating callers of
crc32c_le() that expect a 'const void *' arg to expect 'const u8 *'
instead. Similarly, a future cleanup should remove LIBCRC32C by making
everyone who is selecting it just select CRC32 directly instead.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20241202010844.144356-16-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>

+8 -84
+5 -2
include/linux/crc32c.h
··· 2 2 #ifndef _LINUX_CRC32C_H 3 3 #define _LINUX_CRC32C_H 4 4 5 - #include <linux/types.h> 5 + #include <linux/crc32.h> 6 6 7 - extern u32 crc32c(u32 crc, const void *address, unsigned int length); 7 + static inline u32 crc32c(u32 crc, const void *address, unsigned int length) 8 + { 9 + return __crc32c_le(crc, address, length); 10 + } 8 11 9 12 /* This macro exists for backwards-compatibility. */ 10 13 #define crc32c_le crc32c
+3 -7
lib/Kconfig
··· 310 310 311 311 config LIBCRC32C 312 312 tristate "CRC32c (Castagnoli, et al) Cyclic Redundancy-Check" 313 - select CRYPTO 314 - select CRYPTO_CRC32C 313 + select CRC32 315 314 help 316 - This option is provided for the case where no in-kernel-tree 317 - modules require CRC32c functions, but a module built outside the 318 - kernel tree does. Such modules that use library CRC32c functions 319 - require M here. See Castagnoli93. 320 - Module will be libcrc32c. 315 + This option just selects CRC32 and is provided for compatibility 316 + purposes until the users are updated to select CRC32 directly. 321 317 322 318 config CRC8 323 319 tristate "CRC8 function"
-1
lib/Makefile
··· 167 167 obj-$(CONFIG_CRC32_SELFTEST) += crc32test.o 168 168 obj-$(CONFIG_CRC4) += crc4.o 169 169 obj-$(CONFIG_CRC7) += crc7.o 170 - obj-$(CONFIG_LIBCRC32C) += libcrc32c.o 171 170 obj-$(CONFIG_CRC8) += crc8.o 172 171 obj-$(CONFIG_CRC64_ROCKSOFT) += crc64-rocksoft.o 173 172 obj-$(CONFIG_XXHASH) += xxhash.o
-74
lib/libcrc32c.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * CRC32C 4 - *@Article{castagnoli-crc, 5 - * author = { Guy Castagnoli and Stefan Braeuer and Martin Herrman}, 6 - * title = {{Optimization of Cyclic Redundancy-Check Codes with 24 7 - * and 32 Parity Bits}}, 8 - * journal = IEEE Transactions on Communication, 9 - * year = {1993}, 10 - * volume = {41}, 11 - * number = {6}, 12 - * pages = {}, 13 - * month = {June}, 14 - *} 15 - * Used by the iSCSI driver, possibly others, and derived from 16 - * the iscsi-crc.c module of the linux-iscsi driver at 17 - * http://linux-iscsi.sourceforge.net. 18 - * 19 - * Following the example of lib/crc32, this function is intended to be 20 - * flexible and useful for all users. Modules that currently have their 21 - * own crc32c, but hopefully may be able to use this one are: 22 - * net/sctp (please add all your doco to here if you change to 23 - * use this one!) 24 - * <endoflist> 25 - * 26 - * Copyright (c) 2004 Cisco Systems, Inc. 27 - */ 28 - 29 - #include <crypto/hash.h> 30 - #include <linux/err.h> 31 - #include <linux/init.h> 32 - #include <linux/kernel.h> 33 - #include <linux/module.h> 34 - #include <linux/crc32c.h> 35 - 36 - static struct crypto_shash *tfm; 37 - 38 - u32 crc32c(u32 crc, const void *address, unsigned int length) 39 - { 40 - SHASH_DESC_ON_STACK(shash, tfm); 41 - u32 ret, *ctx = (u32 *)shash_desc_ctx(shash); 42 - int err; 43 - 44 - shash->tfm = tfm; 45 - *ctx = crc; 46 - 47 - err = crypto_shash_update(shash, address, length); 48 - BUG_ON(err); 49 - 50 - ret = *ctx; 51 - barrier_data(ctx); 52 - return ret; 53 - } 54 - 55 - EXPORT_SYMBOL(crc32c); 56 - 57 - static int __init libcrc32c_mod_init(void) 58 - { 59 - tfm = crypto_alloc_shash("crc32c", 0, 0); 60 - return PTR_ERR_OR_ZERO(tfm); 61 - } 62 - 63 - static void __exit libcrc32c_mod_fini(void) 64 - { 65 - crypto_free_shash(tfm); 66 - } 67 - 68 - module_init(libcrc32c_mod_init); 69 - module_exit(libcrc32c_mod_fini); 70 - 71 - MODULE_AUTHOR("Clay Haapala <chaapala@cisco.com>"); 72 - MODULE_DESCRIPTION("CRC32c (Castagnoli) calculations"); 73 - MODULE_LICENSE("GPL"); 74 - MODULE_SOFTDEP("pre: crc32c");