[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210418143425.22944-1-egorenar-dev@posteo.net>
Date: Sun, 18 Apr 2021 14:34:24 +0000
From: Alexander Egorenkov <egorenar-dev@...teo.net>
To: linux-kernel@...r.kernel.org
Cc: Alexander Egorenkov <egorenar-dev@...teo.net>
Subject: [PATCH 1/2] lib: scatterlist: Fix loop termination condition in sg_calculate_split()
nb_splits was decremented one time too much becoming negative. This
leads to the failure of the loop termination conditions which checks
only for nb_splits being zero. Move the loop termination condition
a couple of lines up before nb_splits is decremented again and potentially
becomes negative.
Signed-off-by: Alexander Egorenkov <egorenar-dev@...teo.net>
---
lib/sg_split.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/sg_split.c b/lib/sg_split.c
index 3d9b32084d78..0920affd12ee 100644
--- a/lib/sg_split.c
+++ b/lib/sg_split.c
@@ -60,15 +60,16 @@ static int sg_calculate_split(struct scatterlist *in, int nents, int nb_splits,
curr->length_last_sg = len;
size -= len;
}
- skip = 0;
-
- if (!size && --nb_splits > 0) {
- curr++;
- size = *(++sizes);
- }
if (!nb_splits)
break;
+
+ skip = 0;
+
+ if (!size && --nb_splits > 0) {
+ curr++;
+ size = *(++sizes);
+ }
}
return (size || !splitters[0].in_sg0) ? -EINVAL : 0;
--
2.31.1
Powered by blists - more mailing lists