From 5826f2c8de9c66937e3f5bb5828e2e7db58bf687 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 21 Dec 2020 22:06:06 +0000 Subject: [PATCH] scst: Fix two bugs in error paths Wait for percpu_ref_kill() to finish before calling percpu_ref_exit(). This patch fixes the following complaint: WARNING: CPU: 7 PID: 56710 at lib/percpu-refcount.c:110 percpu_ref_exit+0x28/0x30 RIP: 0010:percpu_ref_exit+0x28/0x30 Call Trace: scst_free_device+0x89/0x120 [scst] scst_register_virtual_device_node+0x27a/0x4f0 [scst] vdisk_add_blockio_device+0x1fa/0x3d0 [scst_vdisk] scst_devt_mgmt_store_work_fn+0x21b/0x2d0 [scst] sysfs_work_thread_fn+0xef/0x400 [scst] kthread+0x112/0x130 Fixes: c5ff6adeaec6 ("Fix unloading of scst_vdisk while I/O is ongoing"; r9048) git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@9229 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index f4f942a18..6fa785d15 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -1057,8 +1057,9 @@ int scst_get_suspend_count(void) static int scst_register_device(struct scsi_device *scsidp) { - int res; + DECLARE_COMPLETION_ONSTACK(c); struct scst_device *dev, *d; + int res; TRACE_ENTRY(); @@ -1128,8 +1129,9 @@ out_del_unlocked: scst_pr_clear_dev(dev); out_free_dev: + dev->remove_completion = &c; percpu_ref_kill(&dev->refcnt); - + wait_for_completion(&c); scst_free_device(dev); out_unlock: @@ -1283,9 +1285,10 @@ out: int scst_register_virtual_device_node(struct scst_dev_type *dev_handler, const char *dev_name, int nodeid) { - int res; + DECLARE_COMPLETION_ONSTACK(c); struct scst_device *dev, *d; bool sysfs_del = false; + int res; TRACE_ENTRY(); @@ -1405,7 +1408,9 @@ out_free_dev: mutex_unlock(&scst_mutex); if (sysfs_del) scst_dev_sysfs_del(dev); + dev->remove_completion = &c; percpu_ref_kill(&dev->refcnt); + wait_for_completion(&c); scst_free_device(dev); goto out;