Skip to content

Commit b7bf54a

Browse files
roxellgregkh
authored andcommitted
writeback: don't decrement wb->refcnt if !wb->bdi
[ Upstream commit 347a28b ] This happened while running in qemu-system-aarch64, the AMBA PL011 UART driver when enabling CONFIG_DEBUG_TEST_DRIVER_REMOVE. arch_initcall(pl011_init) came before subsys_initcall(default_bdi_init), devtmpfs' handle_remove() crashes because the reference count is a NULL pointer only because wb->bdi hasn't been initialized yet. Rework so that wb_put have an extra check if wb->bdi before decrement wb->refcnt and also add a WARN_ON_ONCE to get a warning if it happens again in other drivers. Fixes: 52ebea7 ("writeback: make backing_dev_info host cgroup-specific bdi_writebacks") Co-developed-by: Arnd Bergmann <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Anders Roxell <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 1894718 commit b7bf54a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/backing-dev-defs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ static inline void wb_get(struct bdi_writeback *wb)
233233
*/
234234
static inline void wb_put(struct bdi_writeback *wb)
235235
{
236+
if (WARN_ON_ONCE(!wb->bdi)) {
237+
/*
238+
* A driver bug might cause a file to be removed before bdi was
239+
* initialized.
240+
*/
241+
return;
242+
}
243+
236244
if (wb != &wb->bdi->wb)
237245
percpu_ref_put(&wb->refcnt);
238246
}

0 commit comments

Comments
 (0)