]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/crc32: standardize on crc32c() name for Castagnoli CRC32
authorEric Biggers <ebiggers@google.com>
Sat, 8 Feb 2025 02:49:09 +0000 (18:49 -0800)
committerEric Biggers <ebiggers@google.com>
Sun, 9 Feb 2025 04:06:30 +0000 (20:06 -0800)
For historical reasons, the Castagnoli CRC32 is available under 3 names:
crc32c(), crc32c_le(), and __crc32c_le().  Most callers use crc32c().
The more verbose versions are not really warranted; there is no "_be"
version that the "_le" version needs to be differentiated from, and the
leading underscores are pointless.

Therefore, let's standardize on just crc32c().  Remove the other two
names, and update callers accordingly.

Specifically, the new crc32c() comes from what was previously
__crc32c_le(), so compared to the old crc32c() it now takes a size_t
length rather than unsigned int, and it's now in linux/crc32.h instead
of just linux/crc32c.h (which includes linux/crc32.h).

Later patches will also rename __crc32c_le_combine(), crc32c_le_base(),
and crc32c_le_arch().

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250208024911.14936-5-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
crypto/crc32c_generic.c
drivers/crypto/stm32/stm32-crc32.c
drivers/md/raid5-cache.c
drivers/md/raid5-ppl.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
drivers/thunderbolt/ctl.c
drivers/thunderbolt/eeprom.c
include/linux/crc32.h
include/linux/crc32c.h
include/net/sctp/checksum.h
sound/soc/codecs/aw88395/aw88395_device.c

index 985da981d6e2ac96a03d2a8b17b87cba46131fa0..770533d19b813662da261242a6f5d8d0313f5b42 100644 (file)
@@ -94,7 +94,7 @@ static int chksum_update_arch(struct shash_desc *desc, const u8 *data,
 {
        struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
 
-       ctx->crc = __crc32c_le(ctx->crc, data, length);
+       ctx->crc = crc32c(ctx->crc, data, length);
        return 0;
 }
 
@@ -115,7 +115,7 @@ static int __chksum_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out)
 static int __chksum_finup_arch(u32 *crcp, const u8 *data, unsigned int len,
                               u8 *out)
 {
-       put_unaligned_le32(~__crc32c_le(*crcp, data, len), out);
+       put_unaligned_le32(~crc32c(*crcp, data, len), out);
        return 0;
 }
 
index de4d0402f13391080e5f7719c61f164a28acc4ff..fd29785a3ecf31e6d701960356e05b713d432722 100644 (file)
@@ -162,7 +162,7 @@ static int burst_update(struct shash_desc *desc, const u8 *d8,
                if (mctx->poly == CRC32_POLY_LE)
                        ctx->partial = crc32_le(ctx->partial, d8, length);
                else
-                       ctx->partial = __crc32c_le(ctx->partial, d8, length);
+                       ctx->partial = crc32c(ctx->partial, d8, length);
 
                goto pm_out;
        }
index e530271cb86bbcb477cef6d61c6c33dc68cc3913..ba768ca7f4229e7520ae6f91230bc3bc2d3cd826 100644 (file)
@@ -714,7 +714,7 @@ static void r5l_submit_current_io(struct r5l_log *log)
 
        block = page_address(io->meta_page);
        block->meta_size = cpu_to_le32(io->meta_offset);
-       crc = crc32c_le(log->uuid_checksum, block, PAGE_SIZE);
+       crc = crc32c(log->uuid_checksum, block, PAGE_SIZE);
        block->checksum = cpu_to_le32(crc);
 
        log->current_io = NULL;
@@ -1020,8 +1020,8 @@ int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
                if (test_bit(STRIPE_LOG_TRAPPED, &sh->state))
                        continue;
                addr = kmap_local_page(sh->dev[i].page);
-               sh->dev[i].log_checksum = crc32c_le(log->uuid_checksum,
-                                                   addr, PAGE_SIZE);
+               sh->dev[i].log_checksum = crc32c(log->uuid_checksum,
+                                                addr, PAGE_SIZE);
                kunmap_local(addr);
        }
        parity_pages = 1 + !!(sh->qd_idx >= 0);
@@ -1741,7 +1741,7 @@ static int r5l_recovery_read_meta_block(struct r5l_log *log,
            le64_to_cpu(mb->position) != ctx->pos)
                return -EINVAL;
 
-       crc = crc32c_le(log->uuid_checksum, mb, PAGE_SIZE);
+       crc = crc32c(log->uuid_checksum, mb, PAGE_SIZE);
        if (stored_crc != crc)
                return -EINVAL;
 
@@ -1780,8 +1780,7 @@ static int r5l_log_write_empty_meta_block(struct r5l_log *log, sector_t pos,
                return -ENOMEM;
        r5l_recovery_create_empty_meta_block(log, page, pos, seq);
        mb = page_address(page);
-       mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
-                                            mb, PAGE_SIZE));
+       mb->checksum = cpu_to_le32(crc32c(log->uuid_checksum, mb, PAGE_SIZE));
        if (!sync_page_io(log->rdev, pos, PAGE_SIZE, page, REQ_OP_WRITE |
                          REQ_SYNC | REQ_FUA, false)) {
                __free_page(page);
@@ -1976,7 +1975,7 @@ r5l_recovery_verify_data_checksum(struct r5l_log *log,
 
        r5l_recovery_read_page(log, ctx, page, log_offset);
        addr = kmap_local_page(page);
-       checksum = crc32c_le(log->uuid_checksum, addr, PAGE_SIZE);
+       checksum = crc32c(log->uuid_checksum, addr, PAGE_SIZE);
        kunmap_local(addr);
        return (le32_to_cpu(log_checksum) == checksum) ? 0 : -EINVAL;
 }
@@ -2379,8 +2378,8 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
                                        raid5_compute_blocknr(sh, i, 0));
                                addr = kmap_local_page(dev->page);
                                payload->checksum[0] = cpu_to_le32(
-                                       crc32c_le(log->uuid_checksum, addr,
-                                                 PAGE_SIZE));
+                                       crc32c(log->uuid_checksum, addr,
+                                              PAGE_SIZE));
                                kunmap_local(addr);
                                sync_page_io(log->rdev, write_pos, PAGE_SIZE,
                                             dev->page, REQ_OP_WRITE, false);
@@ -2392,8 +2391,8 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
                        }
                }
                mb->meta_size = cpu_to_le32(offset);
-               mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
-                                                    mb, PAGE_SIZE));
+               mb->checksum = cpu_to_le32(crc32c(log->uuid_checksum,
+                                                 mb, PAGE_SIZE));
                sync_page_io(log->rdev, ctx->pos, PAGE_SIZE, page,
                             REQ_OP_WRITE | REQ_SYNC | REQ_FUA, false);
                sh->log_start = ctx->pos;
@@ -2885,8 +2884,8 @@ int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh)
                if (!test_bit(R5_Wantwrite, &sh->dev[i].flags))
                        continue;
                addr = kmap_local_page(sh->dev[i].page);
-               sh->dev[i].log_checksum = crc32c_le(log->uuid_checksum,
-                                                   addr, PAGE_SIZE);
+               sh->dev[i].log_checksum = crc32c(log->uuid_checksum,
+                                                addr, PAGE_SIZE);
                kunmap_local(addr);
                pages++;
        }
@@ -2969,7 +2968,7 @@ static int r5l_load_log(struct r5l_log *log)
        }
        stored_crc = le32_to_cpu(mb->checksum);
        mb->checksum = 0;
-       expected_crc = crc32c_le(log->uuid_checksum, mb, PAGE_SIZE);
+       expected_crc = crc32c(log->uuid_checksum, mb, PAGE_SIZE);
        if (stored_crc != expected_crc) {
                create_super = true;
                goto create;
@@ -3077,8 +3076,8 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
                return -ENOMEM;
        log->rdev = rdev;
        log->need_cache_flush = bdev_write_cache(rdev->bdev);
-       log->uuid_checksum = crc32c_le(~0, rdev->mddev->uuid,
-                                      sizeof(rdev->mddev->uuid));
+       log->uuid_checksum = crc32c(~0, rdev->mddev->uuid,
+                                   sizeof(rdev->mddev->uuid));
 
        mutex_init(&log->io_mutex);
 
index 37c4da5311ca71aa78e762fef476744678cbb4ca..c0fb335311aa6ca6ceecbb9945d8e582923178d3 100644 (file)
@@ -346,9 +346,9 @@ static int ppl_log_stripe(struct ppl_log *log, struct stripe_head *sh)
        if (!test_bit(STRIPE_FULL_WRITE, &sh->state)) {
                le32_add_cpu(&e->pp_size, PAGE_SIZE);
                io->pp_size += PAGE_SIZE;
-               e->checksum = cpu_to_le32(crc32c_le(le32_to_cpu(e->checksum),
-                                                   page_address(sh->ppl_page),
-                                                   PAGE_SIZE));
+               e->checksum = cpu_to_le32(crc32c(le32_to_cpu(e->checksum),
+                                                page_address(sh->ppl_page),
+                                                PAGE_SIZE));
        }
 
        list_add_tail(&sh->log_list, &io->stripe_list);
@@ -454,7 +454,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io)
        }
 
        pplhdr->entries_count = cpu_to_le32(io->entries_count);
-       pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PPL_HEADER_SIZE));
+       pplhdr->checksum = cpu_to_le32(~crc32c(~0, pplhdr, PPL_HEADER_SIZE));
 
        /* Rewind the buffer if current PPL is larger then remaining space */
        if (log->use_multippl &&
@@ -998,7 +998,7 @@ static int ppl_recover(struct ppl_log *log, struct ppl_header *pplhdr,
                                goto out;
                        }
 
-                       crc = crc32c_le(crc, page_address(page), s);
+                       crc = crc32c(crc, page_address(page), s);
 
                        pp_size -= s;
                        sector += s >> 9;
@@ -1052,7 +1052,7 @@ static int ppl_write_empty_header(struct ppl_log *log)
                            log->rdev->ppl.size, GFP_NOIO, 0);
        memset(pplhdr->reserved, 0xff, PPL_HDR_RESERVED);
        pplhdr->signature = cpu_to_le32(log->ppl_conf->signature);
-       pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PAGE_SIZE));
+       pplhdr->checksum = cpu_to_le32(~crc32c(~0, pplhdr, PAGE_SIZE));
 
        if (!sync_page_io(rdev, rdev->ppl.sector - rdev->data_offset,
                          PPL_HEADER_SIZE, page, REQ_OP_WRITE | REQ_SYNC |
@@ -1106,7 +1106,7 @@ static int ppl_load_distributed(struct ppl_log *log)
                /* check header validity */
                crc_stored = le32_to_cpu(pplhdr->checksum);
                pplhdr->checksum = 0;
-               crc = ~crc32c_le(~0, pplhdr, PAGE_SIZE);
+               crc = ~crc32c(~0, pplhdr, PAGE_SIZE);
 
                if (crc_stored != crc) {
                        pr_debug("%s: ppl header crc does not match: stored: 0x%x calculated: 0x%x (offset: %llu)\n",
@@ -1390,7 +1390,7 @@ int ppl_init_log(struct r5conf *conf)
        spin_lock_init(&ppl_conf->no_mem_stripes_lock);
 
        if (!mddev->external) {
-               ppl_conf->signature = ~crc32c_le(~0, mddev->uuid, sizeof(mddev->uuid));
+               ppl_conf->signature = ~crc32c(~0, mddev->uuid, sizeof(mddev->uuid));
                ppl_conf->block_size = 512;
        } else {
                ppl_conf->block_size =
index 8e04552d2216ce261d18ac8e30e9da52c24f1237..02c8213915a5d673c65771263d4dae7ad81307c4 100644 (file)
@@ -2593,7 +2593,7 @@ void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
 /********************* Multicast verbs: SET, CLEAR ****************************/
 static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
 {
-       return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
+       return (crc32c(0, mac, ETH_ALEN) >> 24) & 0xff;
 }
 
 struct bnx2x_mcast_mac_elem {
index dc1f456736dc4606d6d1e2a51cedf8ffd6149182..cd15e84c47f475994e3b5d02a33d9a2c0ecd3431 100644 (file)
@@ -312,7 +312,7 @@ static void tb_cfg_print_error(struct tb_ctl *ctl, enum tb_cfg_space space,
 
 static __be32 tb_crc(const void *data, size_t len)
 {
-       return cpu_to_be32(~__crc32c_le(~0, data, len));
+       return cpu_to_be32(~crc32c(~0, data, len));
 }
 
 static void tb_ctl_pkg_free(struct ctl_pkg *pkg)
index 9c1d65d2655310a104e75ba18644268da5ebc0cb..e66183a72cf94e03c39be93589d52a5fc6fcf6e7 100644 (file)
@@ -211,7 +211,7 @@ static u8 tb_crc8(u8 *data, int len)
 
 static u32 tb_crc32(void *data, size_t len)
 {
-       return ~__crc32c_le(~0, data, len);
+       return ~crc32c(~0, data, len);
 }
 
 #define TB_DROM_DATA_START             13
index 61a7ec29d633855d4b490a0a1ffa9528c0e92c4f..bc39b023eac0f9c419ed913322bf900237866950 100644 (file)
@@ -29,8 +29,7 @@ static inline u32 crc32_be(u32 crc, const void *p, size_t len)
        return crc32_be_base(crc, p, len);
 }
 
-/* TODO: leading underscores should be dropped once callers have been updated */
-static inline u32 __crc32c_le(u32 crc, const void *p, size_t len)
+static inline u32 crc32c(u32 crc, const void *p, size_t len)
 {
        if (IS_ENABLED(CONFIG_CRC32_ARCH))
                return crc32c_le_arch(crc, p, len);
@@ -45,7 +44,7 @@ static inline u32 __crc32c_le(u32 crc, const void *p, size_t len)
  */
 #define CRC32_LE_OPTIMIZATION  BIT(0) /* crc32_le() is optimized */
 #define CRC32_BE_OPTIMIZATION  BIT(1) /* crc32_be() is optimized */
-#define CRC32C_OPTIMIZATION    BIT(2) /* __crc32c_le() is optimized */
+#define CRC32C_OPTIMIZATION    BIT(2) /* crc32c() is optimized */
 #if IS_ENABLED(CONFIG_CRC32_ARCH)
 u32 crc32_optimizations(void);
 #else
index 47eb78003c2654f419164dd2378015048ab787bc..b8cff2f4309a70efb6521491438dce0be19e0d74 100644 (file)
@@ -4,12 +4,4 @@
 
 #include <linux/crc32.h>
 
-static inline u32 crc32c(u32 crc, const void *address, unsigned int length)
-{
-       return __crc32c_le(crc, address, length);
-}
-
-/* This macro exists for backwards-compatibility. */
-#define crc32c_le crc32c
-
 #endif /* _LINUX_CRC32C_H */
index f514a0aa849eaa7ead9327f6689b6458f38785fb..93041c970753ed27b90e26581be888797cfbf0a5 100644 (file)
@@ -30,9 +30,6 @@
 
 static inline __wsum sctp_csum_update(const void *buff, int len, __wsum sum)
 {
-       /* This uses the crypto implementation of crc32c, which is either
-        * implemented w/ hardware support or resolves to __crc32c_le().
-        */
        return (__force __wsum)crc32c((__force __u32)sum, buff, len);
 }
 
index 6b333d1c6e9461053457399ec186aedb7ecd0615..b7ea8be0d0cb0c412ec1cfae87a774ad47f933d3 100644 (file)
@@ -424,7 +424,7 @@ static int aw_dev_dsp_set_crc32(struct aw_device *aw_dev)
                return -EINVAL;
        }
 
-       crc_value = __crc32c_le(0xFFFFFFFF, crc_dsp_cfg->data, crc_data_len) ^ 0xFFFFFFFF;
+       crc_value = crc32c(0xFFFFFFFF, crc_dsp_cfg->data, crc_data_len) ^ 0xFFFFFFFF;
 
        return aw_dev_dsp_write(aw_dev, AW88395_DSP_REG_CRC_ADDR, crc_value,
                                                AW88395_DSP_32_DATA);