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.

dm-integrity: use internal variable for digestsize

Instead of calling digestsize() each time the digestsize for
the internal hash is needed, store the digestsize in a new
field internal_hash_digestsize within struct dm_integrity_c
once and use this value when needed.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

+14 -11
+14 -11
drivers/md/dm-integrity.c
··· 223 223 int failed; 224 224 225 225 struct crypto_shash *internal_hash; 226 + unsigned int internal_hash_digestsize; 226 227 227 228 struct dm_target *ti; 228 229 ··· 1677 1676 goto failed; 1678 1677 } 1679 1678 1680 - digest_size = crypto_shash_digestsize(ic->internal_hash); 1679 + digest_size = ic->internal_hash_digestsize; 1681 1680 if (unlikely(digest_size < ic->tag_size)) 1682 1681 memset(result + digest_size, 0, ic->tag_size - digest_size); 1683 1682 ··· 1777 1776 if (ic->internal_hash) { 1778 1777 struct bvec_iter iter; 1779 1778 struct bio_vec bv; 1780 - unsigned int digest_size = crypto_shash_digestsize(ic->internal_hash); 1779 + unsigned int digest_size = ic->internal_hash_digestsize; 1781 1780 struct bio *bio = dm_bio_from_per_bio_data(dio, sizeof(struct dm_integrity_io)); 1782 1781 char *checksums; 1783 1782 unsigned int extra_space = unlikely(digest_size > ic->tag_size) ? digest_size - ic->tag_size : 0; ··· 2125 2124 } while (++s < ic->sectors_per_block); 2126 2125 2127 2126 if (ic->internal_hash) { 2128 - unsigned int digest_size = crypto_shash_digestsize(ic->internal_hash); 2127 + unsigned int digest_size = ic->internal_hash_digestsize; 2129 2128 2130 2129 if (unlikely(digest_size > ic->tag_size)) { 2131 2130 char checksums_onstack[HASH_MAX_DIGESTSIZE]; ··· 2429 2428 if (!dio->integrity_payload) { 2430 2429 unsigned digest_size, extra_size; 2431 2430 dio->payload_len = ic->tuple_size * (bio_sectors(bio) >> ic->sb->log2_sectors_per_block); 2432 - digest_size = crypto_shash_digestsize(ic->internal_hash); 2431 + digest_size = ic->internal_hash_digestsize; 2433 2432 extra_size = unlikely(digest_size > ic->tag_size) ? digest_size - ic->tag_size : 0; 2434 2433 dio->payload_len += extra_size; 2435 2434 dio->integrity_payload = kmalloc(dio->payload_len, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); ··· 2590 2589 bio_put(outgoing_bio); 2591 2590 2592 2591 integrity_sector_checksum(ic, dio->bio_details.bi_iter.bi_sector, outgoing_data, digest); 2593 - if (unlikely(crypto_memneq(digest, dio->integrity_payload, min(crypto_shash_digestsize(ic->internal_hash), ic->tag_size)))) { 2592 + if (unlikely(crypto_memneq(digest, dio->integrity_payload, min(ic->internal_hash_digestsize, ic->tag_size)))) { 2594 2593 DMERR_LIMIT("%pg: Checksum failed at sector 0x%llx", 2595 2594 ic->dev->bdev, dio->bio_details.bi_iter.bi_sector); 2596 2595 atomic64_inc(&ic->number_of_mismatches); ··· 2630 2629 //memset(mem, 0xff, ic->sectors_per_block << SECTOR_SHIFT); 2631 2630 integrity_sector_checksum(ic, dio->bio_details.bi_iter.bi_sector, mem, digest); 2632 2631 if (unlikely(crypto_memneq(digest, dio->integrity_payload + pos, 2633 - min(crypto_shash_digestsize(ic->internal_hash), ic->tag_size)))) { 2632 + min(ic->internal_hash_digestsize, ic->tag_size)))) { 2634 2633 kunmap_local(mem); 2635 2634 dm_integrity_free_payload(dio); 2636 2635 INIT_WORK(&dio->work, dm_integrity_inline_recheck); ··· 3012 3011 goto free_ret; 3013 3012 } 3014 3013 recalc_tags_size = (recalc_sectors >> ic->sb->log2_sectors_per_block) * ic->tag_size; 3015 - if (crypto_shash_digestsize(ic->internal_hash) > ic->tag_size) 3016 - recalc_tags_size += crypto_shash_digestsize(ic->internal_hash) - ic->tag_size; 3014 + if (ic->internal_hash_digestsize > ic->tag_size) 3015 + recalc_tags_size += ic->internal_hash_digestsize - ic->tag_size; 3017 3016 recalc_tags = kvmalloc(recalc_tags_size, GFP_NOIO); 3018 3017 if (!recalc_tags) { 3019 3018 vfree(recalc_buffer); ··· 3172 3171 } 3173 3172 3174 3173 recalc_tags_size = (recalc_sectors >> ic->sb->log2_sectors_per_block) * ic->tuple_size; 3175 - if (crypto_shash_digestsize(ic->internal_hash) > ic->tuple_size) 3176 - recalc_tags_size += crypto_shash_digestsize(ic->internal_hash) - ic->tuple_size; 3174 + if (ic->internal_hash_digestsize > ic->tuple_size) 3175 + recalc_tags_size += ic->internal_hash_digestsize - ic->tuple_size; 3177 3176 recalc_tags = kmalloc(recalc_tags_size, GFP_NOIO | __GFP_NOWARN); 3178 3177 if (!recalc_tags) { 3179 3178 kfree(recalc_buffer); ··· 4695 4694 "Invalid internal hash", "Error setting internal hash key"); 4696 4695 if (r) 4697 4696 goto bad; 4697 + if (ic->internal_hash) 4698 + ic->internal_hash_digestsize = crypto_shash_digestsize(ic->internal_hash); 4698 4699 4699 4700 r = get_mac(&ic->journal_mac, &ic->journal_mac_alg, &ti->error, 4700 4701 "Invalid journal mac", "Error setting journal mac key"); ··· 4709 4706 r = -EINVAL; 4710 4707 goto bad; 4711 4708 } 4712 - ic->tag_size = crypto_shash_digestsize(ic->internal_hash); 4709 + ic->tag_size = ic->internal_hash_digestsize; 4713 4710 } 4714 4711 if (ic->tag_size > MAX_TAG_SIZE) { 4715 4712 ti->error = "Too big tag size";