bcachefs: Fix refcounting in discard path
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 Aug 2024 03:21:52 +0000 (23:21 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 Aug 2024 06:07:23 +0000 (02:07 -0400)
commit0b50b7313ef2494926df30ce8e2ce284f1b847fc
treee31051c61b62529648baeabfb05d543268dc5fba
parent8ed823b19214e403ca485532f48c0e02035021ae
bcachefs: Fix refcounting in discard path

bch_dev->io_ref does not protect against the filesystem going away;
bch_fs->writes does.

Thus the filesystem write ref needs to be the last ref we release.

Reported-by: syzbot+9e0404b505e604f67e41@syzkaller.appspotmail.com
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c