]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/crc: Move files into lib/crc/
authorEric Biggers <ebiggers@kernel.org>
Sat, 7 Jun 2025 20:04:43 +0000 (13:04 -0700)
committerEric Biggers <ebiggers@kernel.org>
Mon, 30 Jun 2025 16:31:57 +0000 (09:31 -0700)
Move all CRC files in lib/ into a subdirectory lib/crc/ to keep them
from cluttering up the main lib/ directory.

Reviewed-by: "Martin K. Petersen" <martin.petersen@oracle.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: "Jason A. Donenfeld" <Jason@zx2c4.com>
Link: https://lore.kernel.org/r/20250607200454.73587-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
23 files changed:
Documentation/core-api/kernel-api.rst
MAINTAINERS
include/linux/crc64.h
lib/Kconfig
lib/Kconfig.debug
lib/Makefile
lib/crc/.gitignore [new file with mode: 0644]
lib/crc/Kconfig [new file with mode: 0644]
lib/crc/Makefile [new file with mode: 0644]
lib/crc/crc-ccitt.c [moved from lib/crc-ccitt.c with 98% similarity]
lib/crc/crc-itu-t.c [moved from lib/crc-itu-t.c with 100% similarity]
lib/crc/crc-t10dif.c [moved from lib/crc-t10dif.c with 100% similarity]
lib/crc/crc16.c [moved from lib/crc16.c with 100% similarity]
lib/crc/crc32.c [moved from lib/crc32.c with 100% similarity]
lib/crc/crc4.c [moved from lib/crc4.c with 100% similarity]
lib/crc/crc64.c [moved from lib/crc64.c with 100% similarity]
lib/crc/crc7.c [moved from lib/crc7.c with 100% similarity]
lib/crc/crc8.c [moved from lib/crc8.c with 100% similarity]
lib/crc/gen_crc32table.c [moved from lib/gen_crc32table.c with 95% similarity]
lib/crc/gen_crc64table.c [moved from lib/gen_crc64table.c with 81% similarity]
lib/crc/tests/Makefile [new file with mode: 0644]
lib/crc/tests/crc_kunit.c [moved from lib/tests/crc_kunit.c with 100% similarity]
lib/tests/Makefile

index ae92a2571388ae7fc0b7c5f23a19ed59ac1312cc..c4642d9f13a9cd42bf24769d7d77f075f476b2ec 100644 (file)
@@ -136,24 +136,24 @@ Arithmetic Overflow Checking
 CRC Functions
 -------------
 
-.. kernel-doc:: lib/crc4.c
+.. kernel-doc:: lib/crc/crc4.c
    :export:
 
-.. kernel-doc:: lib/crc7.c
+.. kernel-doc:: lib/crc/crc7.c
    :export:
 
-.. kernel-doc:: lib/crc8.c
+.. kernel-doc:: lib/crc/crc8.c
    :export:
 
-.. kernel-doc:: lib/crc16.c
+.. kernel-doc:: lib/crc/crc16.c
    :export:
 
-.. kernel-doc:: lib/crc32.c
+.. kernel-doc:: lib/crc/crc32.c
 
-.. kernel-doc:: lib/crc-ccitt.c
+.. kernel-doc:: lib/crc/crc-ccitt.c
    :export:
 
-.. kernel-doc:: lib/crc-itu-t.c
+.. kernel-doc:: lib/crc/crc-itu-t.c
    :export:
 
 Base 2 log and power Functions
index 4bac4ea21b64445069e1518bd906354627dca438..b0ec17dfbe0353a79e91175f2669ffb3db7dee86 100644 (file)
@@ -6361,8 +6361,7 @@ T:        git https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git crc-ne
 F:     Documentation/staging/crc*
 F:     arch/*/lib/crc*
 F:     include/linux/crc*
-F:     lib/crc*
-F:     lib/tests/crc_kunit.c
+F:     lib/crc/
 F:     scripts/gen-crc-consts.py
 
 CREATIVE SB0540
index 41de30b907dff891fec961a05b12474a234104b0..b6aa290a79312fe2f52138f1a0ff441fde0cf1ff 100644 (file)
@@ -1,7 +1,4 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-/*
- * See lib/crc64.c for the related specification and polynomial arithmetic.
- */
 #ifndef _LINUX_CRC64_H
 #define _LINUX_CRC64_H
 
index 37db228f70a99fb5cf563ec10f707cb605c4e508..c483951b624ff8111217b25598bd574b8ff18193 100644 (file)
@@ -136,95 +136,9 @@ config TRACE_MMIO_ACCESS
          Create tracepoints for MMIO read/write operations. These trace events
          can be used for logging all MMIO read/write operations.
 
+source "lib/crc/Kconfig"
 source "lib/crypto/Kconfig"
 
-config CRC_CCITT
-       tristate
-       help
-         The CRC-CCITT library functions.  Select this if your module uses any
-         of the functions from <linux/crc-ccitt.h>.
-
-config CRC16
-       tristate
-       help
-         The CRC16 library functions.  Select this if your module uses any of
-         the functions from <linux/crc16.h>.
-
-config CRC_T10DIF
-       tristate
-       help
-         The CRC-T10DIF library functions.  Select this if your module uses
-         any of the functions from <linux/crc-t10dif.h>.
-
-config ARCH_HAS_CRC_T10DIF
-       bool
-
-config CRC_T10DIF_ARCH
-       tristate
-       default CRC_T10DIF if ARCH_HAS_CRC_T10DIF && CRC_OPTIMIZATIONS
-
-config CRC_ITU_T
-       tristate
-       help
-         The CRC-ITU-T library functions.  Select this if your module uses
-         any of the functions from <linux/crc-itu-t.h>.
-
-config CRC32
-       tristate
-       select BITREVERSE
-       help
-         The CRC32 library functions.  Select this if your module uses any of
-         the functions from <linux/crc32.h> or <linux/crc32c.h>.
-
-config ARCH_HAS_CRC32
-       bool
-
-config CRC32_ARCH
-       tristate
-       default CRC32 if ARCH_HAS_CRC32 && CRC_OPTIMIZATIONS
-
-config CRC64
-       tristate
-       help
-         The CRC64 library functions.  Select this if your module uses any of
-         the functions from <linux/crc64.h>.
-
-config ARCH_HAS_CRC64
-       bool
-
-config CRC64_ARCH
-       tristate
-       default CRC64 if ARCH_HAS_CRC64 && CRC_OPTIMIZATIONS
-
-config CRC4
-       tristate
-       help
-         The CRC4 library functions.  Select this if your module uses any of
-         the functions from <linux/crc4.h>.
-
-config CRC7
-       tristate
-       help
-         The CRC7 library functions.  Select this if your module uses any of
-         the functions from <linux/crc7.h>.
-
-config CRC8
-       tristate
-       help
-         The CRC8 library functions.  Select this if your module uses any of
-         the functions from <linux/crc8.h>.
-
-config CRC_OPTIMIZATIONS
-       bool "Enable optimized CRC implementations" if EXPERT
-       default y
-       help
-         Disabling this option reduces code size slightly by disabling the
-         architecture-optimized implementations of any CRC variants that are
-         enabled.  CRC checksumming performance may get much slower.
-
-         Keep this enabled unless you're really trying to minimize the size of
-         the kernel.
-
 config XXHASH
        tristate
 
index ebe33181b6e6e0fb4243b400e9187881707efe23..3fda96761adbc209b6db43da2e80ad40668c9085 100644 (file)
@@ -2901,27 +2901,6 @@ config HW_BREAKPOINT_KUNIT_TEST
 
          If unsure, say N.
 
-config CRC_KUNIT_TEST
-       tristate "KUnit tests for CRC functions" if !KUNIT_ALL_TESTS
-       depends on KUNIT
-       default KUNIT_ALL_TESTS
-       select CRC7
-       select CRC16
-       select CRC_T10DIF
-       select CRC32
-       select CRC64
-       help
-         Unit tests for the CRC library functions.
-
-         This is intended to help people writing architecture-specific
-         optimized versions.  If unsure, say N.
-
-config CRC_BENCHMARK
-       bool "Benchmark for the CRC functions"
-       depends on CRC_KUNIT_TEST
-       help
-         Include benchmarks in the KUnit test suite for the CRC functions.
-
 config SIPHASH_KUNIT_TEST
        tristate "Perform selftest on siphash functions" if !KUNIT_ALL_TESTS
        depends on KUNIT
index c38582f187dd81916113319072e5cfef26f26c84..14a5928bb57f52fabe8635e9209b91d24680c9b3 100644 (file)
@@ -122,7 +122,7 @@ endif
 obj-$(CONFIG_DEBUG_INFO_REDUCED) += debug_info.o
 CFLAGS_debug_info.o += $(call cc-option, -femit-struct-debug-detailed=any)
 
-obj-y += math/ crypto/ tests/ vdso/
+obj-y += math/ crc/ crypto/ tests/ vdso/
 
 obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
 obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
@@ -148,15 +148,6 @@ obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-$(CONFIG_LINEAR_RANGES) += linear_ranges.o
 obj-$(CONFIG_PACKING)  += packing.o
 obj-$(CONFIG_PACKING_KUNIT_TEST) += packing_test.o
-obj-$(CONFIG_CRC_CCITT)        += crc-ccitt.o
-obj-$(CONFIG_CRC16)    += crc16.o
-obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o
-obj-$(CONFIG_CRC_ITU_T)        += crc-itu-t.o
-obj-$(CONFIG_CRC32)    += crc32.o
-obj-$(CONFIG_CRC64)     += crc64.o
-obj-$(CONFIG_CRC4)     += crc4.o
-obj-$(CONFIG_CRC7)     += crc7.o
-obj-$(CONFIG_CRC8)     += crc8.o
 obj-$(CONFIG_XXHASH)   += xxhash.o
 obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o
 
@@ -294,27 +285,6 @@ obj-$(CONFIG_ASN1_ENCODER) += asn1_encoder.o
 
 obj-$(CONFIG_FONT_SUPPORT) += fonts/
 
-hostprogs      := gen_crc32table
-hostprogs      += gen_crc64table
-clean-files    := crc32table.h
-clean-files    += crc64table.h
-
-$(obj)/crc32.o: $(obj)/crc32table.h
-
-quiet_cmd_crc32 = GEN     $@
-      cmd_crc32 = $< > $@
-
-$(obj)/crc32table.h: $(obj)/gen_crc32table
-       $(call cmd,crc32)
-
-$(obj)/crc64.o: $(obj)/crc64table.h
-
-quiet_cmd_crc64 = GEN     $@
-      cmd_crc64 = $< > $@
-
-$(obj)/crc64table.h: $(obj)/gen_crc64table
-       $(call cmd,crc64)
-
 #
 # Build a fast OID lookip registry from include/linux/oid_registry.h
 #
diff --git a/lib/crc/.gitignore b/lib/crc/.gitignore
new file mode 100644 (file)
index 0000000..a9e4810
--- /dev/null
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+/crc32table.h
+/crc64table.h
+/gen_crc32table
+/gen_crc64table
diff --git a/lib/crc/Kconfig b/lib/crc/Kconfig
new file mode 100644 (file)
index 0000000..e0e7168
--- /dev/null
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Kconfig for the kernel's cyclic redundancy check (CRC) library code
+
+config CRC4
+       tristate
+       help
+         The CRC4 library functions.  Select this if your module uses any of
+         the functions from <linux/crc4.h>.
+
+config CRC7
+       tristate
+       help
+         The CRC7 library functions.  Select this if your module uses any of
+         the functions from <linux/crc7.h>.
+
+config CRC8
+       tristate
+       help
+         The CRC8 library functions.  Select this if your module uses any of
+         the functions from <linux/crc8.h>.
+
+config CRC16
+       tristate
+       help
+         The CRC16 library functions.  Select this if your module uses any of
+         the functions from <linux/crc16.h>.
+
+config CRC_CCITT
+       tristate
+       help
+         The CRC-CCITT library functions.  Select this if your module uses any
+         of the functions from <linux/crc-ccitt.h>.
+
+config CRC_ITU_T
+       tristate
+       help
+         The CRC-ITU-T library functions.  Select this if your module uses
+         any of the functions from <linux/crc-itu-t.h>.
+
+config CRC_T10DIF
+       tristate
+       help
+         The CRC-T10DIF library functions.  Select this if your module uses
+         any of the functions from <linux/crc-t10dif.h>.
+
+config ARCH_HAS_CRC_T10DIF
+       bool
+
+config CRC_T10DIF_ARCH
+       tristate
+       default CRC_T10DIF if ARCH_HAS_CRC_T10DIF && CRC_OPTIMIZATIONS
+
+config CRC32
+       tristate
+       select BITREVERSE
+       help
+         The CRC32 library functions.  Select this if your module uses any of
+         the functions from <linux/crc32.h> or <linux/crc32c.h>.
+
+config ARCH_HAS_CRC32
+       bool
+
+config CRC32_ARCH
+       tristate
+       default CRC32 if ARCH_HAS_CRC32 && CRC_OPTIMIZATIONS
+
+config CRC64
+       tristate
+       help
+         The CRC64 library functions.  Select this if your module uses any of
+         the functions from <linux/crc64.h>.
+
+config ARCH_HAS_CRC64
+       bool
+
+config CRC64_ARCH
+       tristate
+       default CRC64 if ARCH_HAS_CRC64 && CRC_OPTIMIZATIONS
+
+config CRC_OPTIMIZATIONS
+       bool "Enable optimized CRC implementations" if EXPERT
+       default y
+       help
+         Disabling this option reduces code size slightly by disabling the
+         architecture-optimized implementations of any CRC variants that are
+         enabled.  CRC checksumming performance may get much slower.
+
+         Keep this enabled unless you're really trying to minimize the size of
+         the kernel.
+
+config CRC_KUNIT_TEST
+       tristate "KUnit tests for CRC functions" if !KUNIT_ALL_TESTS
+       depends on KUNIT
+       default KUNIT_ALL_TESTS
+       select CRC7
+       select CRC16
+       select CRC_T10DIF
+       select CRC32
+       select CRC64
+       help
+         Unit tests for the CRC library functions.
+
+         This is intended to help people writing architecture-specific
+         optimized versions.  If unsure, say N.
+
+config CRC_BENCHMARK
+       bool "Benchmark for the CRC functions"
+       depends on CRC_KUNIT_TEST
+       help
+         Include benchmarks in the KUnit test suite for the CRC functions.
diff --git a/lib/crc/Makefile b/lib/crc/Makefile
new file mode 100644 (file)
index 0000000..ff4c30d
--- /dev/null
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+# Makefile for the kernel's cyclic redundancy check (CRC) library code
+
+obj-$(CONFIG_CRC4) += crc4.o
+obj-$(CONFIG_CRC7) += crc7.o
+obj-$(CONFIG_CRC8) += crc8.o
+obj-$(CONFIG_CRC16) += crc16.o
+obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
+obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o
+obj-$(CONFIG_CRC_T10DIF) += crc-t10dif.o
+obj-$(CONFIG_CRC32) += crc32.o
+obj-$(CONFIG_CRC64) += crc64.o
+obj-y += tests/
+
+hostprogs := gen_crc32table gen_crc64table
+clean-files := crc32table.h crc64table.h
+
+$(obj)/crc32.o: $(obj)/crc32table.h
+$(obj)/crc64.o: $(obj)/crc64table.h
+
+quiet_cmd_crc32 = GEN     $@
+      cmd_crc32 = $< > $@
+
+quiet_cmd_crc64 = GEN     $@
+      cmd_crc64 = $< > $@
+
+$(obj)/crc32table.h: $(obj)/gen_crc32table
+       $(call cmd,crc32)
+
+$(obj)/crc64table.h: $(obj)/gen_crc64table
+       $(call cmd,crc64)
similarity index 98%
rename from lib/crc-ccitt.c
rename to lib/crc/crc-ccitt.c
index 9cddf35d3b66ecfca96ecbb4586945fa609887ca..8d2bc419230b31f0aa1e2ce92c9f5e3b3e854aee 100644 (file)
@@ -1,7 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0-only
-/*
- *     linux/lib/crc-ccitt.c
- */
 
 #include <linux/types.h>
 #include <linux/module.h>
similarity index 100%
rename from lib/crc-itu-t.c
rename to lib/crc/crc-itu-t.c
similarity index 100%
rename from lib/crc-t10dif.c
rename to lib/crc/crc-t10dif.c
similarity index 100%
rename from lib/crc16.c
rename to lib/crc/crc16.c
similarity index 100%
rename from lib/crc32.c
rename to lib/crc/crc32.c
similarity index 100%
rename from lib/crc4.c
rename to lib/crc/crc4.c
similarity index 100%
rename from lib/crc64.c
rename to lib/crc/crc64.c
similarity index 100%
rename from lib/crc7.c
rename to lib/crc/crc7.c
similarity index 100%
rename from lib/crc8.c
rename to lib/crc/crc8.c
similarity index 95%
rename from lib/gen_crc32table.c
rename to lib/crc/gen_crc32table.c
index 6d03425b849e43962fd537bb90ab5deb78b49a4c..9a7f31658e3554f386ccc2b90fb99694203469d4 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <stdio.h>
-#include "../include/linux/crc32poly.h"
-#include "../include/generated/autoconf.h"
+#include "../../include/linux/crc32poly.h"
+#include "../../include/generated/autoconf.h"
 #include <inttypes.h>
 
 static uint32_t crc32table_le[256];
similarity index 81%
rename from lib/gen_crc64table.c
rename to lib/crc/gen_crc64table.c
index e05a4230a0a0826473aa8c6ac74d38b6b4c82291..f2be9f62bab716bea0f445b5df78d951502e6f0a 100644 (file)
@@ -1,14 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Generate lookup table for the table-driven CRC64 calculation.
- *
- * gen_crc64table is executed in kernel build time and generates
- * lib/crc64table.h. This header is included by lib/crc64.c for
- * the table-driven CRC64 calculation.
- *
- * See lib/crc64.c for more information about which specification
- * and polynomial arithmetic that gen_crc64table.c follows to
- * generate the lookup table.
+ * This host program runs at kernel build time and generates the lookup tables
+ * used by the generic CRC64 code.
  *
  * Copyright 2018 SUSE Linux.
  *   Author: Coly Li <colyli@suse.de>
diff --git a/lib/crc/tests/Makefile b/lib/crc/tests/Makefile
new file mode 100644 (file)
index 0000000..65f63c3
--- /dev/null
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_CRC_KUNIT_TEST) += crc_kunit.o
index 56d6450144828ee7bfe27878d3fca33dc863fd3d..741d3ac2cba252592c7abc982f89012fa5dfd3bd 100644 (file)
@@ -10,7 +10,6 @@ obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
 obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
 obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
 obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
-obj-$(CONFIG_CRC_KUNIT_TEST) += crc_kunit.o
 CFLAGS_fortify_kunit.o += $(call cc-disable-warning, unsequenced)
 CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-overread)
 CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-truncation)