bcachefs: fix integer underflow in journal code

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2019-02-27 19:14:23 -05:00 committed by Kent Overstreet
parent 28062d320b
commit 8db2acde2f
2 changed files with 5 additions and 1 deletions

View File

@ -256,6 +256,8 @@ static int journal_entry_open(struct journal *j)
do {
old.v = new.v = v;
EBUG_ON(journal_state_count(new, new.idx));
if (old.cur_entry_offset == JOURNAL_ENTRY_ERROR_VAL)
return -EROFS;
@ -429,7 +431,7 @@ void bch2_journal_entry_res_resize(struct journal *j,
if (d <= 0)
goto out;
j->cur_entry_u64s -= d;
j->cur_entry_u64s = max_t(int, 0, j->cur_entry_u64s - d);
smp_mb();
state = READ_ONCE(j->reservations);

View File

@ -292,6 +292,8 @@ static inline int journal_res_get_fast(struct journal *j,
if (new.cur_entry_offset + res->u64s > j->cur_entry_u64s)
return 0;
EBUG_ON(!journal_state_count(new, new.idx));
if (flags & JOURNAL_RES_GET_CHECK)
return 1;