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: compute target region directly

Instead of determining the target block's region by checking which block
of the k blocks being iterated over in fec_read_bufs() is equal to the
target block, instead just directly use the quotient of the division of
target_block by region_blocks.

This is the same value, just derived in a more straightforward way.

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
ca21ed40 ca0da6cc

+16 -21
+16 -21
drivers/md/dm-verity-fec.c
··· 49 49 * the corrected bytes into fio->output starting from out_pos. 50 50 */ 51 51 static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_io *io, 52 - struct dm_verity_fec_io *fio, u64 rsb, int byte_index, 53 - unsigned int out_pos, int neras) 52 + struct dm_verity_fec_io *fio, u64 rsb, 53 + int target_region, unsigned int out_pos, int neras) 54 54 { 55 55 int r, corrected = 0, res; 56 56 struct dm_buffer *buf; ··· 120 120 } 121 121 122 122 corrected += res; 123 - fio->output[out_pos++] = msg_buf[byte_index]; 123 + fio->output[out_pos++] = msg_buf[target_region]; 124 124 125 125 if (out_pos >= v->fec->block_size) 126 126 goto done; ··· 158 158 * fits into buffers. Check for erasure locations if @neras is non-NULL. 159 159 */ 160 160 static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, 161 - u64 rsb, u64 target, unsigned int out_pos, int *neras) 161 + u64 rsb, unsigned int out_pos, int *neras) 162 162 { 163 163 bool is_zero; 164 - int i, j, target_index = -1; 164 + int i, j; 165 165 struct dm_buffer *buf; 166 166 struct dm_bufio_client *bufio; 167 167 struct dm_verity_fec_io *fio = io->fec_io; ··· 183 183 */ 184 184 for (i = 0; i < v->fec->rs_k; i++) { 185 185 ileaved = rsb + i * (v->fec->region_blocks << v->data_dev_block_bits); 186 - 187 - /* 188 - * target is the data block we want to correct, target_index is 189 - * the index of this block within the rs_k RS blocks 190 - */ 191 - if (ileaved == target) 192 - target_index = i; 193 - 194 186 block = ileaved >> v->data_dev_block_bits; 195 187 bufio = v->fec->data_bufio; 196 188 ··· 244 252 done: 245 253 dm_bufio_release(buf); 246 254 } 247 - 248 - return target_index; 255 + return 0; 249 256 } 250 257 251 258 /* ··· 311 320 const u8 *want_digest, bool use_erasures) 312 321 { 313 322 int r, neras = 0; 314 - unsigned int out_pos; 315 - u64 offset = target_block << v->data_dev_block_bits; 323 + unsigned int target_region, out_pos; 316 324 u64 rsb; 317 325 318 - div64_u64_rem(offset, v->fec->region_blocks << v->data_dev_block_bits, 319 - &rsb); 326 + target_region = div64_u64_rem( 327 + target_block << v->data_dev_block_bits, 328 + v->fec->region_blocks << v->data_dev_block_bits, &rsb); 329 + if (WARN_ON_ONCE(target_region >= v->fec->rs_k)) 330 + /* target_block is out-of-bounds. Should never happen. */ 331 + return -EIO; 320 332 321 333 for (out_pos = 0; out_pos < v->fec->block_size;) { 322 334 fec_init_bufs(v, fio); 323 335 324 - r = fec_read_bufs(v, io, rsb, offset, out_pos, 336 + r = fec_read_bufs(v, io, rsb, out_pos, 325 337 use_erasures ? &neras : NULL); 326 338 if (unlikely(r < 0)) 327 339 return r; 328 340 329 - r = fec_decode_bufs(v, io, fio, rsb, r, out_pos, neras); 341 + r = fec_decode_bufs(v, io, fio, rsb, target_region, 342 + out_pos, neras); 330 343 if (r < 0) 331 344 return r; 332 345