summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/rebalance.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-08-17 22:35:58 +0200
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 23:10:11 +0200
commitd0445e131e3ff1a68492f7f6e754cd672db4774d (patch)
tree0a2aed5d330ee2b8e7797aade67e8e2114f8784b /fs/bcachefs/rebalance.c
parentbcachefs: Split out snapshot.c (diff)
downloadlinux-d0445e131e3ff1a68492f7f6e754cd672db4774d.tar.xz
linux-d0445e131e3ff1a68492f7f6e754cd672db4774d.zip
bcachefs: Fix divide by zero in rebalance_work()
This fixes https://github.com/koverstreet/bcachefs-tools/issues/159 Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to '')
-rw-r--r--fs/bcachefs/rebalance.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c
index c3d577236ce2..15ce3ecba0ba 100644
--- a/fs/bcachefs/rebalance.c
+++ b/fs/bcachefs/rebalance.c
@@ -113,6 +113,10 @@ static void rebalance_work_accumulate(struct rebalance_work *w,
unsigned percent_full;
u64 work = dev_work + unknown_dev;
+ /* avoid divide by 0 */
+ if (!capacity)
+ return;
+
if (work < dev_work || work < unknown_dev)
work = U64_MAX;
work = min(work, capacity);