Convert cpu_to_le64(le64_to_cpu(E1) + E2) to use le64_add_cpu().
Signed-off-by: Liu Shixin <[email protected]>
---
drivers/md/dm-integrity.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
index 3fc3757def55..cf9dadd55625 100644
--- a/drivers/md/dm-integrity.c
+++ b/drivers/md/dm-integrity.c
@@ -3696,7 +3696,7 @@ static int create_journal(struct dm_integrity_c *ic, char **error)
retest_commit_id:
for (j = 0; j < i; j++) {
if (ic->commit_ids[j] == ic->commit_ids[i]) {
- ic->commit_ids[i] = cpu_to_le64(le64_to_cpu(ic->commit_ids[i]) + 1);
+ le64_add_cpu(&ic->commit_ids[i], 1);
goto retest_commit_id;
}
}
--
2.25.1
Hi Liu,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on next-20200911]
url: https://github.com/0day-ci/linux/commits/Liu-Shixin/dm-integrity-convert-to-use-le64_add_cpu/20200914-115650
base: d5b2251d63b5344ee827d3680fa79bdb9f9ddfa1
config: x86_64-randconfig-s022-20200914 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.2-191-g10164920-dirty
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
sparse warnings: (new ones prefixed by >>)
drivers/md/dm-integrity.c:2672:25: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:2712:25: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] sector_hi @@ got restricted __le32 [usertype] @@
drivers/md/dm-integrity.c:2712:25: sparse: expected unsigned int [usertype] sector_hi
drivers/md/dm-integrity.c:2712:25: sparse: got restricted __le32 [usertype]
drivers/md/dm-integrity.c:2784:38: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:2945:31: sparse: sparse: invalid assignment: &=
drivers/md/dm-integrity.c:2945:31: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:2945:31: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:2960:43: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:2977:47: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] provided_data_sectors @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:2977:47: sparse: expected unsigned long long [usertype] provided_data_sectors
drivers/md/dm-integrity.c:2977:47: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:2983:29: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:2993:55: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:2993:55: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:2993:55: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:2994:63: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] recalc_sector @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:2994:63: sparse: expected unsigned long long [usertype] recalc_sector
drivers/md/dm-integrity.c:2994:63: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3005:47: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:3005:47: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:3005:47: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:3006:55: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] recalc_sector @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3006:55: sparse: expected unsigned long long [usertype] recalc_sector
drivers/md/dm-integrity.c:3006:55: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3011:47: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:3011:47: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:3011:47: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:3012:55: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] recalc_sector @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3012:55: sparse: expected unsigned long long [usertype] recalc_sector
drivers/md/dm-integrity.c:3012:55: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3016:39: sparse: sparse: invalid assignment: &=
drivers/md/dm-integrity.c:3016:39: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:3016:39: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:3024:39: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:3024:39: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:3024:39: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:3033:45: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3034:29: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3035:66: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3036:77: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3037:72: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3038:77: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3039:75: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3040:77: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3048:29: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3049:36: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3054:47: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] recalc_sector @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3054:47: sparse: expected unsigned long long [usertype] recalc_sector
drivers/md/dm-integrity.c:3054:47: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3082:37: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3083:25: sparse: sparse: cast to restricted __le64
drivers/md/dm-integrity.c:3095:49: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3104:47: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3111:37: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3126:38: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3171:32: sparse: sparse: cast to restricted __le32
drivers/md/dm-integrity.c:3175:29: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3198:41: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:3253:36: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned short [usertype] integrity_tag_size @@ got restricted __le16 [usertype] @@
drivers/md/dm-integrity.c:3253:36: sparse: expected unsigned short [usertype] integrity_tag_size
drivers/md/dm-integrity.c:3253:36: sparse: got restricted __le16 [usertype]
drivers/md/dm-integrity.c:3256:31: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:3256:31: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:3256:31: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:3265:39: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:3265:39: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:3265:39: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:3266:42: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] journal_sections @@ got restricted __le32 [usertype] @@
drivers/md/dm-integrity.c:3266:42: sparse: expected unsigned int [usertype] journal_sections
drivers/md/dm-integrity.c:3266:42: sparse: got restricted __le32 [usertype]
drivers/md/dm-integrity.c:3284:42: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] journal_sections @@ got restricted __le32 [usertype] @@
drivers/md/dm-integrity.c:3284:42: sparse: expected unsigned int [usertype] journal_sections
drivers/md/dm-integrity.c:3284:42: sparse: got restricted __le32 [usertype]
drivers/md/dm-integrity.c:3286:55: sparse: sparse: cast to restricted __le32
drivers/md/dm-integrity.c:3290:50: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] journal_sections @@ got restricted __le32 [usertype] @@
drivers/md/dm-integrity.c:3290:50: sparse: expected unsigned int [usertype] journal_sections
drivers/md/dm-integrity.c:3290:50: sparse: got restricted __le32 [usertype]
drivers/md/dm-integrity.c:3292:58: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] journal_sections @@ got restricted __le32 [usertype] @@
drivers/md/dm-integrity.c:3292:58: sparse: expected unsigned int [usertype] journal_sections
drivers/md/dm-integrity.c:3292:58: sparse: got restricted __le32 [usertype]
drivers/md/dm-integrity.c:3295:22: sparse: sparse: cast to restricted __le32
drivers/md/dm-integrity.c:3304:39: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] provided_data_sectors @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3304:39: sparse: expected unsigned long long [usertype] provided_data_sectors
drivers/md/dm-integrity.c:3304:39: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3496:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3496:27: sparse: expected unsigned long long
drivers/md/dm-integrity.c:3496:27: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3497:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3497:27: sparse: expected unsigned long long
drivers/md/dm-integrity.c:3497:27: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3498:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3498:27: sparse: expected unsigned long long
drivers/md/dm-integrity.c:3498:27: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3499:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:3499:27: sparse: expected unsigned long long
drivers/md/dm-integrity.c:3499:27: sparse: got restricted __le64 [usertype]
drivers/md/dm-integrity.c:3653:52: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned int [usertype] section_le @@ got restricted __le32 [usertype] @@
drivers/md/dm-integrity.c:3653:52: sparse: expected unsigned int [usertype] section_le
drivers/md/dm-integrity.c:3653:52: sparse: got restricted __le32 [usertype]
>> drivers/md/dm-integrity.c:3699:61: sparse: sparse: incorrect type in argument 1 (different base types) @@ expected restricted __le64 [usertype] *var @@ got unsigned long long * @@
>> drivers/md/dm-integrity.c:3699:61: sparse: expected restricted __le64 [usertype] *var
>> drivers/md/dm-integrity.c:3699:61: sparse: got unsigned long long *
drivers/md/dm-integrity.c:4066:13: sparse: sparse: cast to restricted __le16
drivers/md/dm-integrity.c:4076:14: sparse: sparse: cast to restricted __le32
drivers/md/dm-integrity.c:4096:32: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:4174:55: sparse: sparse: restricted __le32 degrades to integer
drivers/md/dm-integrity.c:4175:31: sparse: sparse: invalid assignment: |=
drivers/md/dm-integrity.c:4175:31: sparse: left side has type unsigned int
drivers/md/dm-integrity.c:4175:31: sparse: right side has type restricted __le32
drivers/md/dm-integrity.c:4176:39: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] recalc_sector @@ got restricted __le64 [usertype] @@
drivers/md/dm-integrity.c:4176:39: sparse: expected unsigned long long [usertype] recalc_sector
drivers/md/dm-integrity.c:4176:39: sparse: got restricted __le64 [usertype]
# https://github.com/0day-ci/linux/commit/d0fe72210efe84e8e9c90b1650eb8a5728378dbe
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Liu-Shixin/dm-integrity-convert-to-use-le64_add_cpu/20200914-115650
git checkout d0fe72210efe84e8e9c90b1650eb8a5728378dbe
vim +3699 drivers/md/dm-integrity.c
3487
3488 static int create_journal(struct dm_integrity_c *ic, char **error)
3489 {
3490 int r = 0;
3491 unsigned i;
3492 __u64 journal_pages, journal_desc_size, journal_tree_size;
3493 unsigned char *crypt_data = NULL, *crypt_iv = NULL;
3494 struct skcipher_request *req = NULL;
3495
3496 ic->commit_ids[0] = cpu_to_le64(0x1111111111111111ULL);
3497 ic->commit_ids[1] = cpu_to_le64(0x2222222222222222ULL);
3498 ic->commit_ids[2] = cpu_to_le64(0x3333333333333333ULL);
3499 ic->commit_ids[3] = cpu_to_le64(0x4444444444444444ULL);
3500
3501 journal_pages = roundup((__u64)ic->journal_sections * ic->journal_section_sectors,
3502 PAGE_SIZE >> SECTOR_SHIFT) >> (PAGE_SHIFT - SECTOR_SHIFT);
3503 journal_desc_size = journal_pages * sizeof(struct page_list);
3504 if (journal_pages >= totalram_pages() - totalhigh_pages() || journal_desc_size > ULONG_MAX) {
3505 *error = "Journal doesn't fit into memory";
3506 r = -ENOMEM;
3507 goto bad;
3508 }
3509 ic->journal_pages = journal_pages;
3510
3511 ic->journal = dm_integrity_alloc_page_list(ic->journal_pages);
3512 if (!ic->journal) {
3513 *error = "Could not allocate memory for journal";
3514 r = -ENOMEM;
3515 goto bad;
3516 }
3517 if (ic->journal_crypt_alg.alg_string) {
3518 unsigned ivsize, blocksize;
3519 struct journal_completion comp;
3520
3521 comp.ic = ic;
3522 ic->journal_crypt = crypto_alloc_skcipher(ic->journal_crypt_alg.alg_string, 0, 0);
3523 if (IS_ERR(ic->journal_crypt)) {
3524 *error = "Invalid journal cipher";
3525 r = PTR_ERR(ic->journal_crypt);
3526 ic->journal_crypt = NULL;
3527 goto bad;
3528 }
3529 ivsize = crypto_skcipher_ivsize(ic->journal_crypt);
3530 blocksize = crypto_skcipher_blocksize(ic->journal_crypt);
3531
3532 if (ic->journal_crypt_alg.key) {
3533 r = crypto_skcipher_setkey(ic->journal_crypt, ic->journal_crypt_alg.key,
3534 ic->journal_crypt_alg.key_size);
3535 if (r) {
3536 *error = "Error setting encryption key";
3537 goto bad;
3538 }
3539 }
3540 DEBUG_print("cipher %s, block size %u iv size %u\n",
3541 ic->journal_crypt_alg.alg_string, blocksize, ivsize);
3542
3543 ic->journal_io = dm_integrity_alloc_page_list(ic->journal_pages);
3544 if (!ic->journal_io) {
3545 *error = "Could not allocate memory for journal io";
3546 r = -ENOMEM;
3547 goto bad;
3548 }
3549
3550 if (blocksize == 1) {
3551 struct scatterlist *sg;
3552
3553 req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL);
3554 if (!req) {
3555 *error = "Could not allocate crypt request";
3556 r = -ENOMEM;
3557 goto bad;
3558 }
3559
3560 crypt_iv = kzalloc(ivsize, GFP_KERNEL);
3561 if (!crypt_iv) {
3562 *error = "Could not allocate iv";
3563 r = -ENOMEM;
3564 goto bad;
3565 }
3566
3567 ic->journal_xor = dm_integrity_alloc_page_list(ic->journal_pages);
3568 if (!ic->journal_xor) {
3569 *error = "Could not allocate memory for journal xor";
3570 r = -ENOMEM;
3571 goto bad;
3572 }
3573
3574 sg = kvmalloc_array(ic->journal_pages + 1,
3575 sizeof(struct scatterlist),
3576 GFP_KERNEL);
3577 if (!sg) {
3578 *error = "Unable to allocate sg list";
3579 r = -ENOMEM;
3580 goto bad;
3581 }
3582 sg_init_table(sg, ic->journal_pages + 1);
3583 for (i = 0; i < ic->journal_pages; i++) {
3584 char *va = lowmem_page_address(ic->journal_xor[i].page);
3585 clear_page(va);
3586 sg_set_buf(&sg[i], va, PAGE_SIZE);
3587 }
3588 sg_set_buf(&sg[i], &ic->commit_ids, sizeof ic->commit_ids);
3589
3590 skcipher_request_set_crypt(req, sg, sg,
3591 PAGE_SIZE * ic->journal_pages + sizeof ic->commit_ids, crypt_iv);
3592 init_completion(&comp.comp);
3593 comp.in_flight = (atomic_t)ATOMIC_INIT(1);
3594 if (do_crypt(true, req, &comp))
3595 wait_for_completion(&comp.comp);
3596 kvfree(sg);
3597 r = dm_integrity_failed(ic);
3598 if (r) {
3599 *error = "Unable to encrypt journal";
3600 goto bad;
3601 }
3602 DEBUG_bytes(lowmem_page_address(ic->journal_xor[0].page), 64, "xor data");
3603
3604 crypto_free_skcipher(ic->journal_crypt);
3605 ic->journal_crypt = NULL;
3606 } else {
3607 unsigned crypt_len = roundup(ivsize, blocksize);
3608
3609 req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL);
3610 if (!req) {
3611 *error = "Could not allocate crypt request";
3612 r = -ENOMEM;
3613 goto bad;
3614 }
3615
3616 crypt_iv = kmalloc(ivsize, GFP_KERNEL);
3617 if (!crypt_iv) {
3618 *error = "Could not allocate iv";
3619 r = -ENOMEM;
3620 goto bad;
3621 }
3622
3623 crypt_data = kmalloc(crypt_len, GFP_KERNEL);
3624 if (!crypt_data) {
3625 *error = "Unable to allocate crypt data";
3626 r = -ENOMEM;
3627 goto bad;
3628 }
3629
3630 ic->journal_scatterlist = dm_integrity_alloc_journal_scatterlist(ic, ic->journal);
3631 if (!ic->journal_scatterlist) {
3632 *error = "Unable to allocate sg list";
3633 r = -ENOMEM;
3634 goto bad;
3635 }
3636 ic->journal_io_scatterlist = dm_integrity_alloc_journal_scatterlist(ic, ic->journal_io);
3637 if (!ic->journal_io_scatterlist) {
3638 *error = "Unable to allocate sg list";
3639 r = -ENOMEM;
3640 goto bad;
3641 }
3642 ic->sk_requests = kvmalloc_array(ic->journal_sections,
3643 sizeof(struct skcipher_request *),
3644 GFP_KERNEL | __GFP_ZERO);
3645 if (!ic->sk_requests) {
3646 *error = "Unable to allocate sk requests";
3647 r = -ENOMEM;
3648 goto bad;
3649 }
3650 for (i = 0; i < ic->journal_sections; i++) {
3651 struct scatterlist sg;
3652 struct skcipher_request *section_req;
3653 __u32 section_le = cpu_to_le32(i);
3654
3655 memset(crypt_iv, 0x00, ivsize);
3656 memset(crypt_data, 0x00, crypt_len);
3657 memcpy(crypt_data, §ion_le, min((size_t)crypt_len, sizeof(section_le)));
3658
3659 sg_init_one(&sg, crypt_data, crypt_len);
3660 skcipher_request_set_crypt(req, &sg, &sg, crypt_len, crypt_iv);
3661 init_completion(&comp.comp);
3662 comp.in_flight = (atomic_t)ATOMIC_INIT(1);
3663 if (do_crypt(true, req, &comp))
3664 wait_for_completion(&comp.comp);
3665
3666 r = dm_integrity_failed(ic);
3667 if (r) {
3668 *error = "Unable to generate iv";
3669 goto bad;
3670 }
3671
3672 section_req = skcipher_request_alloc(ic->journal_crypt, GFP_KERNEL);
3673 if (!section_req) {
3674 *error = "Unable to allocate crypt request";
3675 r = -ENOMEM;
3676 goto bad;
3677 }
3678 section_req->iv = kmalloc_array(ivsize, 2,
3679 GFP_KERNEL);
3680 if (!section_req->iv) {
3681 skcipher_request_free(section_req);
3682 *error = "Unable to allocate iv";
3683 r = -ENOMEM;
3684 goto bad;
3685 }
3686 memcpy(section_req->iv + ivsize, crypt_data, ivsize);
3687 section_req->cryptlen = (size_t)ic->journal_section_sectors << SECTOR_SHIFT;
3688 ic->sk_requests[i] = section_req;
3689 DEBUG_bytes(crypt_data, ivsize, "iv(%u)", i);
3690 }
3691 }
3692 }
3693
3694 for (i = 0; i < N_COMMIT_IDS; i++) {
3695 unsigned j;
3696 retest_commit_id:
3697 for (j = 0; j < i; j++) {
3698 if (ic->commit_ids[j] == ic->commit_ids[i]) {
> 3699 le64_add_cpu(&ic->commit_ids[i], 1);
3700 goto retest_commit_id;
3701 }
3702 }
3703 DEBUG_print("commit id %u: %016llx\n", i, ic->commit_ids[i]);
3704 }
3705
3706 journal_tree_size = (__u64)ic->journal_entries * sizeof(struct journal_node);
3707 if (journal_tree_size > ULONG_MAX) {
3708 *error = "Journal doesn't fit into memory";
3709 r = -ENOMEM;
3710 goto bad;
3711 }
3712 ic->journal_tree = kvmalloc(journal_tree_size, GFP_KERNEL);
3713 if (!ic->journal_tree) {
3714 *error = "Could not allocate memory for journal tree";
3715 r = -ENOMEM;
3716 }
3717 bad:
3718 kfree(crypt_data);
3719 kfree(crypt_iv);
3720 skcipher_request_free(req);
3721
3722 return r;
3723 }
3724
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]