Skip to content

Commit 4f111bb

Browse files
dedekindJiri Slaby
authored andcommitted
UBIFS: fix free log space calculation
commit ba29e72 upstream. 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. Tested-by: hujianyang <hujianyang@huawei.com> Reported-by: hujianyang <hujianyang@huawei.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
1 parent c52a279 commit 4f111bb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎fs/ubifs/log.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ static inline long long empty_log_bytes(const struct ubifs_info *c)
106106
h = (long long)c->lhead_lnum * c->leb_size + c->lhead_offs;
107107
t = (long long)c->ltail_lnum * c->leb_size;
108108

109-
if (h >= t)
109+
if (h > t)
110110
return c->log_bytes - h + t;
111-
else
111+
else if (h != t)
112112
return t - h;
113+
else if (c->lhead_lnum != c->ltail_lnum)
114+
return 0;
115+
else
116+
return c->log_bytes;
113117
}
114118

115119
/**

0 commit comments

Comments
 (0)