From 1c468a0f66963efb4e2ef40579065dae336a8c2f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 15 May 2019 10:14:19 +0900 Subject: [PATCH] dif: Merge two code blocks into a single while loop in set_md_interleave_iovs By clearing head_align to zero after using it, we can merge two code blocks into a single while loop, and replace goto by simple break. Change-Id: Ia63cd0d7dbf4b9dddf7da93e11351bb46bd04791 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/454394 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- lib/util/dif.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/util/dif.c b/lib/util/dif.c index 08a00ca10..c3d323665 100644 --- a/lib/util/dif.c +++ b/lib/util/dif.c @@ -1327,26 +1327,19 @@ spdk_dif_set_md_interleave_iovs(struct iovec *iovs, int iovcnt, _dif_sgl_init(&sgl, iovs, iovcnt); buf += offset_blocks * ctx->block_size; - if (head_unalign != 0) { + while (offset_blocks < num_blocks) { buf += head_unalign; if (!_dif_sgl_append(&sgl, buf, data_block_size - head_unalign)) { - goto end; + break; } buf += ctx->block_size - head_unalign; offset_blocks++; + + head_unalign = 0; } - while (offset_blocks < num_blocks) { - if (!_dif_sgl_append(&sgl, buf, data_block_size)) { - goto end; - } - buf += ctx->block_size; - offset_blocks++; - } - -end: if (_mapped_len != NULL) { *_mapped_len = sgl.total_size; }