Skip to contentSkip to conversation

bcache: fix up kthread_stop crash in cached_dev_free()

PATCH New Mingzhe Zou 1 participant 1 message Apr 25, 2023 bcache (block layer cache)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcache: fix up kthread_stop crash in cached_dev_free()

In bch_cached_dev_attach(), writeback kthread stopped if bch_cached_dev_run() returns error. Then, cached_dev_free() will stop writeback kthread again and crash.

This patch set dc->writeback_thread to null after call kthread_stop().

Fixes 5c2a634cbfaf ("bcache: stop writeback kthread and kworker when bch_cached_dev_run() failed")
---
 drivers/md/bcache/super.c | 1 +
 1 file changed, 1 insertion(+)
drivers/md/bcache/super.c +1 -0
index ba3909bb6bea..7b6e533b0339 100644
@@ -1310,6 +1310,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
 		 * have to be stopped manually here.
 		 */
 		kthread_stop(dc->writeback_thread);
+		dc->writeback_thread = NULL;
 		cancel_writeback_rate_update_dwork(dc);
 		pr_err("Couldn't run cached device %pg\n", dc->bdev);
 		return ret;
Signature · 1 line
2.17.1.windows.2