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: c5ff6adeae ("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
This commit is contained in:
Bart Van Assche
2020-12-21 22:06:06 +00:00
parent e3d187f6af
commit 5826f2c8de

View File

@@ -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;