From 3bcc08ebed1a51d1d4b8be74ca4b52556d80d564 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 10 Mar 2019 04:38:33 +0000 Subject: [PATCH] scst_vdisk: Hold a reference on the associated struct scst_device git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8031 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index d09b55ce1..e280cea16 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1308,13 +1308,17 @@ next: res = scst_pr_set_cluster_mode(dev, dev->cluster_mode, virt_dev->t10_dev_id); + if (res) + goto out; + + percpu_ref_get(&dev->refcnt); out: TRACE_EXIT(); return res; } -/* scst_mutex supposed to be held */ +/* Detach a virtual device from a device. scst_mutex is supposed to be held. */ static void vdisk_detach(struct scst_device *dev) { struct scst_vdisk_dev *virt_dev = dev->dh_priv; @@ -1332,6 +1336,8 @@ static void vdisk_detach(struct scst_device *dev) /* virt_dev will be freed by the caller */ dev->dh_priv = NULL; + virt_dev->dev = NULL; + percpu_ref_put(&dev->refcnt); TRACE_EXIT(); return;