Skip to content

Commit 368686a

Browse files
roxelltorvalds
authored andcommitted
writeback: don't decrement wb->refcnt if !wb->bdi
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. Link: http://lkml.kernel.org/r/20181030113545.30999-2-anders.roxell@linaro.org Fixes: 52ebea7 ("writeback: make backing_dev_info host cgroup-specific bdi_writebacks") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Anders Roxell <anders.roxell@linaro.org> Co-developed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6a90a83 commit 368686a

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
@@ -258,6 +258,14 @@ static inline void wb_get(struct bdi_writeback *wb)
258258
*/
259259
static inline void wb_put(struct bdi_writeback *wb)
260260
{
261+
if (WARN_ON_ONCE(!wb->bdi)) {
262+
/*
263+
* A driver bug might cause a file to be removed before bdi was
264+
* initialized.
265+
*/
266+
return;
267+
}
268+
261269
if (wb != &wb->bdi->wb)
262270
percpu_ref_put(&wb->refcnt);
263271
}

0 commit comments

Comments
 (0)