Commit 8db2acde authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: fix integer underflow in journal code

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 28062d32
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment