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-verity-fec: simplify computation of ileaved

fec_read_bufs() just iterates over a sequence of message blocks with
step size region_blocks. At each step, 'ileaved' is just the offset (in
bytes) to one of these blocks. Compute it in the straightforward way,
eliminating fec_interleave().

In more detail, previously the code computed
'ileaved = (n / k) + (n % k) * (region_blocks * block_size)'
where n = rsb * k + i and 0 <= i < k. Substituting 'n' gives:

ileaved = ((rsb * k + i) / k) + ((rsb * k + i) % k) * region_blocks * block_size
= rsb + (i * region_blocks * block_size)

The result is more efficient and easier to understand.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Eric Biggers and committed by
Mikulas Patocka
5ef22361 8ef45923

+1 -12
+1 -12
drivers/md/dm-verity-fec.c
··· 23 23 return 1 << (v->data_dev_block_bits - DM_VERITY_FEC_BUF_RS_BITS); 24 24 } 25 25 26 - /* 27 - * Return an interleaved offset for a byte in RS block. 28 - */ 29 - static inline u64 fec_interleave(struct dm_verity *v, u64 offset) 30 - { 31 - u32 mod; 32 - 33 - mod = do_div(offset, v->fec->rs_k); 34 - return offset + mod * (v->fec->region_blocks << v->data_dev_block_bits); 35 - } 36 - 37 26 /* Loop over each allocated buffer. */ 38 27 #define fec_for_each_buffer(io, __i) \ 39 28 for (__i = 0; __i < (io)->nbufs; __i++) ··· 193 204 * interleave contents to available bufs 194 205 */ 195 206 for (i = 0; i < v->fec->rs_k; i++) { 196 - ileaved = fec_interleave(v, rsb * v->fec->rs_k + i); 207 + ileaved = rsb + i * (v->fec->region_blocks << v->data_dev_block_bits); 197 208 198 209 /* 199 210 * target is the data block we want to correct, target_index is