linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] UBIFS: fix free log space calculation
@ 2014-07-16 12:42 Artem Bityutskiy
  2014-07-16 12:42 ` [PATCH 2/2] UBIFS: add a log overlap assertion Artem Bityutskiy
  2014-08-11  3:21 ` [PATCH 1/2] UBIFS: fix free log space calculation hujianyang
  0 siblings, 2 replies; 7+ messages in thread
From: Artem Bityutskiy @ 2014-07-16 12:42 UTC (permalink / raw)
  To: hujianyang; +Cc: MTD Maling List

From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

Hu (hujianyang <hujianyang@huawei.com>) discovered an issue in the
'empty_log_bytes()' function, which calculates how many bytes are left in the
log:

"
If 'c->lhead_lnum + 1 == c->ltail_lnum' and 'c->lhead_offs == c->leb_size', 'h'
would equalent to 't' and 'empty_log_bytes()' would return 'c->log_bytes'
instead of 0.
"

At this point it is not clear what would be the consequences of this, and
whether this may lead to any problems, but this patch addresses the issue just
in case.

Reported-by: hujianyang <hujianyang@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
 fs/ubifs/log.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/ubifs/log.c b/fs/ubifs/log.c
index ed24422..7e818ec 100644
--- a/fs/ubifs/log.c
+++ b/fs/ubifs/log.c
@@ -106,10 +106,14 @@ static inline long long empty_log_bytes(const struct ubifs_info *c)
 	h = (long long)c->lhead_lnum * c->leb_size + c->lhead_offs;
 	t = (long long)c->ltail_lnum * c->leb_size;
 
-	if (h >= t)
+	if (h > t)
 		return c->log_bytes - h + t;
-	else
+	else if (h != t)
 		return t - h;
+	else if (c->lhead_lnum != c->ltail_lnum)
+		return 0;
+	else
+		return c->log_bytes;
 }
 
 /**
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-08  9:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-16 12:42 [PATCH 1/2] UBIFS: fix free log space calculation Artem Bityutskiy
2014-07-16 12:42 ` [PATCH 2/2] UBIFS: add a log overlap assertion Artem Bityutskiy
2014-07-22  1:35   ` hujianyang
2014-07-28 16:18     ` Artem Bityutskiy
2014-07-29 10:27       ` hujianyang
2014-08-11  3:21 ` [PATCH 1/2] UBIFS: fix free log space calculation hujianyang
2014-09-08  9:43   ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).