Skip to content

Commit 8df3682

Browse files
committed
lib/crc32: standardize on crc32c() name for Castagnoli CRC32
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent bc2736f commit 8df3682

File tree

11 files changed

+32
-45
lines changed

11 files changed

+32
-45
lines changed

crypto/crc32c_generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int chksum_update_arch(struct shash_desc *desc, const u8 *data,
9494
{
9595
struct chksum_desc_ctx *ctx = shash_desc_ctx(desc);
9696

97-
ctx->crc = __crc32c_le(ctx->crc, data, length);
97+
ctx->crc = crc32c(ctx->crc, data, length);
9898
return 0;
9999
}
100100

@@ -115,7 +115,7 @@ static int __chksum_finup(u32 *crcp, const u8 *data, unsigned int len, u8 *out)
115115
static int __chksum_finup_arch(u32 *crcp, const u8 *data, unsigned int len,
116116
u8 *out)
117117
{
118-
put_unaligned_le32(~__crc32c_le(*crcp, data, len), out);
118+
put_unaligned_le32(~crc32c(*crcp, data, len), out);
119119
return 0;
120120
}
121121

drivers/crypto/stm32/stm32-crc32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static int burst_update(struct shash_desc *desc, const u8 *d8,
162162
if (mctx->poly == CRC32_POLY_LE)
163163
ctx->partial = crc32_le(ctx->partial, d8, length);
164164
else
165-
ctx->partial = __crc32c_le(ctx->partial, d8, length);
165+
ctx->partial = crc32c(ctx->partial, d8, length);
166166

167167
goto pm_out;
168168
}

drivers/md/raid5-cache.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static void r5l_submit_current_io(struct r5l_log *log)
714714

715715
block = page_address(io->meta_page);
716716
block->meta_size = cpu_to_le32(io->meta_offset);
717-
crc = crc32c_le(log->uuid_checksum, block, PAGE_SIZE);
717+
crc = crc32c(log->uuid_checksum, block, PAGE_SIZE);
718718
block->checksum = cpu_to_le32(crc);
719719

720720
log->current_io = NULL;
@@ -1020,8 +1020,8 @@ int r5l_write_stripe(struct r5l_log *log, struct stripe_head *sh)
10201020
if (test_bit(STRIPE_LOG_TRAPPED, &sh->state))
10211021
continue;
10221022
addr = kmap_local_page(sh->dev[i].page);
1023-
sh->dev[i].log_checksum = crc32c_le(log->uuid_checksum,
1024-
addr, PAGE_SIZE);
1023+
sh->dev[i].log_checksum = crc32c(log->uuid_checksum,
1024+
addr, PAGE_SIZE);
10251025
kunmap_local(addr);
10261026
}
10271027
parity_pages = 1 + !!(sh->qd_idx >= 0);
@@ -1741,7 +1741,7 @@ static int r5l_recovery_read_meta_block(struct r5l_log *log,
17411741
le64_to_cpu(mb->position) != ctx->pos)
17421742
return -EINVAL;
17431743

1744-
crc = crc32c_le(log->uuid_checksum, mb, PAGE_SIZE);
1744+
crc = crc32c(log->uuid_checksum, mb, PAGE_SIZE);
17451745
if (stored_crc != crc)
17461746
return -EINVAL;
17471747

@@ -1780,8 +1780,7 @@ static int r5l_log_write_empty_meta_block(struct r5l_log *log, sector_t pos,
17801780
return -ENOMEM;
17811781
r5l_recovery_create_empty_meta_block(log, page, pos, seq);
17821782
mb = page_address(page);
1783-
mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
1784-
mb, PAGE_SIZE));
1783+
mb->checksum = cpu_to_le32(crc32c(log->uuid_checksum, mb, PAGE_SIZE));
17851784
if (!sync_page_io(log->rdev, pos, PAGE_SIZE, page, REQ_OP_WRITE |
17861785
REQ_SYNC | REQ_FUA, false)) {
17871786
__free_page(page);
@@ -1976,7 +1975,7 @@ r5l_recovery_verify_data_checksum(struct r5l_log *log,
19761975

19771976
r5l_recovery_read_page(log, ctx, page, log_offset);
19781977
addr = kmap_local_page(page);
1979-
checksum = crc32c_le(log->uuid_checksum, addr, PAGE_SIZE);
1978+
checksum = crc32c(log->uuid_checksum, addr, PAGE_SIZE);
19801979
kunmap_local(addr);
19811980
return (le32_to_cpu(log_checksum) == checksum) ? 0 : -EINVAL;
19821981
}
@@ -2379,8 +2378,8 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
23792378
raid5_compute_blocknr(sh, i, 0));
23802379
addr = kmap_local_page(dev->page);
23812380
payload->checksum[0] = cpu_to_le32(
2382-
crc32c_le(log->uuid_checksum, addr,
2383-
PAGE_SIZE));
2381+
crc32c(log->uuid_checksum, addr,
2382+
PAGE_SIZE));
23842383
kunmap_local(addr);
23852384
sync_page_io(log->rdev, write_pos, PAGE_SIZE,
23862385
dev->page, REQ_OP_WRITE, false);
@@ -2392,8 +2391,8 @@ r5c_recovery_rewrite_data_only_stripes(struct r5l_log *log,
23922391
}
23932392
}
23942393
mb->meta_size = cpu_to_le32(offset);
2395-
mb->checksum = cpu_to_le32(crc32c_le(log->uuid_checksum,
2396-
mb, PAGE_SIZE));
2394+
mb->checksum = cpu_to_le32(crc32c(log->uuid_checksum,
2395+
mb, PAGE_SIZE));
23972396
sync_page_io(log->rdev, ctx->pos, PAGE_SIZE, page,
23982397
REQ_OP_WRITE | REQ_SYNC | REQ_FUA, false);
23992398
sh->log_start = ctx->pos;
@@ -2885,8 +2884,8 @@ int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh)
28852884
if (!test_bit(R5_Wantwrite, &sh->dev[i].flags))
28862885
continue;
28872886
addr = kmap_local_page(sh->dev[i].page);
2888-
sh->dev[i].log_checksum = crc32c_le(log->uuid_checksum,
2889-
addr, PAGE_SIZE);
2887+
sh->dev[i].log_checksum = crc32c(log->uuid_checksum,
2888+
addr, PAGE_SIZE);
28902889
kunmap_local(addr);
28912890
pages++;
28922891
}
@@ -2969,7 +2968,7 @@ static int r5l_load_log(struct r5l_log *log)
29692968
}
29702969
stored_crc = le32_to_cpu(mb->checksum);
29712970
mb->checksum = 0;
2972-
expected_crc = crc32c_le(log->uuid_checksum, mb, PAGE_SIZE);
2971+
expected_crc = crc32c(log->uuid_checksum, mb, PAGE_SIZE);
29732972
if (stored_crc != expected_crc) {
29742973
create_super = true;
29752974
goto create;
@@ -3077,8 +3076,8 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
30773076
return -ENOMEM;
30783077
log->rdev = rdev;
30793078
log->need_cache_flush = bdev_write_cache(rdev->bdev);
3080-
log->uuid_checksum = crc32c_le(~0, rdev->mddev->uuid,
3081-
sizeof(rdev->mddev->uuid));
3079+
log->uuid_checksum = crc32c(~0, rdev->mddev->uuid,
3080+
sizeof(rdev->mddev->uuid));
30823081

30833082
mutex_init(&log->io_mutex);
30843083

drivers/md/raid5-ppl.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ static int ppl_log_stripe(struct ppl_log *log, struct stripe_head *sh)
346346
if (!test_bit(STRIPE_FULL_WRITE, &sh->state)) {
347347
le32_add_cpu(&e->pp_size, PAGE_SIZE);
348348
io->pp_size += PAGE_SIZE;
349-
e->checksum = cpu_to_le32(crc32c_le(le32_to_cpu(e->checksum),
350-
page_address(sh->ppl_page),
351-
PAGE_SIZE));
349+
e->checksum = cpu_to_le32(crc32c(le32_to_cpu(e->checksum),
350+
page_address(sh->ppl_page),
351+
PAGE_SIZE));
352352
}
353353

354354
list_add_tail(&sh->log_list, &io->stripe_list);
@@ -454,7 +454,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io)
454454
}
455455

456456
pplhdr->entries_count = cpu_to_le32(io->entries_count);
457-
pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PPL_HEADER_SIZE));
457+
pplhdr->checksum = cpu_to_le32(~crc32c(~0, pplhdr, PPL_HEADER_SIZE));
458458

459459
/* Rewind the buffer if current PPL is larger then remaining space */
460460
if (log->use_multippl &&
@@ -998,7 +998,7 @@ static int ppl_recover(struct ppl_log *log, struct ppl_header *pplhdr,
998998
goto out;
999999
}
10001000

1001-
crc = crc32c_le(crc, page_address(page), s);
1001+
crc = crc32c(crc, page_address(page), s);
10021002

10031003
pp_size -= s;
10041004
sector += s >> 9;
@@ -1052,7 +1052,7 @@ static int ppl_write_empty_header(struct ppl_log *log)
10521052
log->rdev->ppl.size, GFP_NOIO, 0);
10531053
memset(pplhdr->reserved, 0xff, PPL_HDR_RESERVED);
10541054
pplhdr->signature = cpu_to_le32(log->ppl_conf->signature);
1055-
pplhdr->checksum = cpu_to_le32(~crc32c_le(~0, pplhdr, PAGE_SIZE));
1055+
pplhdr->checksum = cpu_to_le32(~crc32c(~0, pplhdr, PAGE_SIZE));
10561056

10571057
if (!sync_page_io(rdev, rdev->ppl.sector - rdev->data_offset,
10581058
PPL_HEADER_SIZE, page, REQ_OP_WRITE | REQ_SYNC |
@@ -1106,7 +1106,7 @@ static int ppl_load_distributed(struct ppl_log *log)
11061106
/* check header validity */
11071107
crc_stored = le32_to_cpu(pplhdr->checksum);
11081108
pplhdr->checksum = 0;
1109-
crc = ~crc32c_le(~0, pplhdr, PAGE_SIZE);
1109+
crc = ~crc32c(~0, pplhdr, PAGE_SIZE);
11101110

11111111
if (crc_stored != crc) {
11121112
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)
13901390
spin_lock_init(&ppl_conf->no_mem_stripes_lock);
13911391

13921392
if (!mddev->external) {
1393-
ppl_conf->signature = ~crc32c_le(~0, mddev->uuid, sizeof(mddev->uuid));
1393+
ppl_conf->signature = ~crc32c(~0, mddev->uuid, sizeof(mddev->uuid));
13941394
ppl_conf->block_size = 512;
13951395
} else {
13961396
ppl_conf->block_size =

drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2593,7 +2593,7 @@ void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
25932593
/********************* Multicast verbs: SET, CLEAR ****************************/
25942594
static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
25952595
{
2596-
return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
2596+
return (crc32c(0, mac, ETH_ALEN) >> 24) & 0xff;
25972597
}
25982598

25992599
struct bnx2x_mcast_mac_elem {

drivers/thunderbolt/ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static void tb_cfg_print_error(struct tb_ctl *ctl, enum tb_cfg_space space,
312312

313313
static __be32 tb_crc(const void *data, size_t len)
314314
{
315-
return cpu_to_be32(~__crc32c_le(~0, data, len));
315+
return cpu_to_be32(~crc32c(~0, data, len));
316316
}
317317

318318
static void tb_ctl_pkg_free(struct ctl_pkg *pkg)

drivers/thunderbolt/eeprom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static u8 tb_crc8(u8 *data, int len)
211211

212212
static u32 tb_crc32(void *data, size_t len)
213213
{
214-
return ~__crc32c_le(~0, data, len);
214+
return ~crc32c(~0, data, len);
215215
}
216216

217217
#define TB_DROM_DATA_START 13

include/linux/crc32.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ static inline u32 crc32_be(u32 crc, const void *p, size_t len)
2929
return crc32_be_base(crc, p, len);
3030
}
3131

32-
/* TODO: leading underscores should be dropped once callers have been updated */
33-
static inline u32 __crc32c_le(u32 crc, const void *p, size_t len)
32+
static inline u32 crc32c(u32 crc, const void *p, size_t len)
3433
{
3534
if (IS_ENABLED(CONFIG_CRC32_ARCH))
3635
return crc32c_le_arch(crc, p, len);
@@ -45,7 +44,7 @@ static inline u32 __crc32c_le(u32 crc, const void *p, size_t len)
4544
*/
4645
#define CRC32_LE_OPTIMIZATION BIT(0) /* crc32_le() is optimized */
4746
#define CRC32_BE_OPTIMIZATION BIT(1) /* crc32_be() is optimized */
48-
#define CRC32C_OPTIMIZATION BIT(2) /* __crc32c_le() is optimized */
47+
#define CRC32C_OPTIMIZATION BIT(2) /* crc32c() is optimized */
4948
#if IS_ENABLED(CONFIG_CRC32_ARCH)
5049
u32 crc32_optimizations(void);
5150
#else

include/linux/crc32c.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,4 @@
44

55
#include <linux/crc32.h>
66

7-
static inline u32 crc32c(u32 crc, const void *address, unsigned int length)
8-
{
9-
return __crc32c_le(crc, address, length);
10-
}
11-
12-
/* This macro exists for backwards-compatibility. */
13-
#define crc32c_le crc32c
14-
157
#endif /* _LINUX_CRC32C_H */

include/net/sctp/checksum.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030

3131
static inline __wsum sctp_csum_update(const void *buff, int len, __wsum sum)
3232
{
33-
/* This uses the crypto implementation of crc32c, which is either
34-
* implemented w/ hardware support or resolves to __crc32c_le().
35-
*/
3633
return (__force __wsum)crc32c((__force __u32)sum, buff, len);
3734
}
3835

0 commit comments

Comments
 (0)