From b7f80e05667bc6a5ee7537b1b74d5db9a0ad4ea1 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 8 May 2014 02:28:49 +0000 Subject: [PATCH] Avoid that the code for dumping the PR state triggers a race condition Callers of scst_pr_dump_prs() must hold dev_pr_mutex. Signed-off-by: Bart Van Assche git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5508 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_proc.c | 7 ++++++- scst/src/scst_sysfs.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index 91e4101c6..2a3bc1981 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -397,7 +397,12 @@ int scst_proc_log_entry_write(struct file *file, const char __user *buf, list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { if (strcmp(dev->virt_name, p) == 0) { - scst_pr_dump_prs(dev, true); + if (mutex_lock_interruptible(&dev->dev_pr_mutex) == 0) { + scst_pr_dump_prs(dev, true); + mutex_unlock(&dev->dev_pr_mutex); + } else { + res = -EINTR; + } goto out_up; } } diff --git a/scst/src/scst_sysfs.c b/scst/src/scst_sysfs.c index a6bda65bd..5187d104d 100644 --- a/scst/src/scst_sysfs.c +++ b/scst/src/scst_sysfs.c @@ -2762,15 +2762,23 @@ static ssize_t scst_dev_sysfs_dump_prs(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { struct scst_device *dev; + int res; TRACE_ENTRY(); dev = container_of(kobj, struct scst_device, dev_kobj); + res = mutex_lock_interruptible(&dev->dev_pr_mutex); + if (res != 0) + goto out; scst_pr_dump_prs(dev, true); + mutex_unlock(&dev->dev_pr_mutex); - TRACE_EXIT_RES(count); - return count; + res = count; + +out: + TRACE_EXIT_RES(res); + return res; } static struct kobj_attribute dev_dump_prs_attr =