From: Andreas Gruenbacher <agruenba@redhat.com>
Date: Tue, 4 Dec 2018 14:06:27 +0000 (+0100)
Subject: gfs2: Fix loop in gfs2_rbm_find
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=2d29f6b96d;p=linux.git

gfs2: Fix loop in gfs2_rbm_find

Fix the resource group wrap-around logic in gfs2_rbm_find that commit
e579ed4f44 broke.  The bug can lead to unnecessary repeated scanning of the
same bitmaps; there is a risk that future changes will turn this into an
endless loop.

Fixes: e579ed4f44 ("GFS2: Introduce rbm field bii")
Cc: stable@vger.kernel.org # v3.13+
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index b08a530433adf..8d79165703621 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -1780,9 +1780,9 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
 			goto next_iter;
 		}
 		if (ret == -E2BIG) {
+			n += rbm->bii - initial_bii;
 			rbm->bii = 0;
 			rbm->offset = 0;
-			n += (rbm->bii - initial_bii);
 			goto res_covered_end_of_rgrp;
 		}
 		return ret;