1 From 78727137fdf49edf9f731bde79d7189067b4047a Mon Sep 17 00:00:00 2001
2 From: Dan Williams <dan.j.williams@intel.com>
3 Date: Mon, 2 Apr 2018 16:40:04 -0700
4 Subject: nfit, address-range-scrub: fix scrub in-progress reporting
6 From: Dan Williams <dan.j.williams@intel.com>
8 commit 78727137fdf49edf9f731bde79d7189067b4047a upstream.
10 There is a small window whereby ARS scan requests can schedule work that
11 userspace will miss when polling scrub_show. Hold the init_mutex lock
12 over calls to report the status to close this potential escape. Also,
13 make sure that requests to cancel the ARS workqueue are treated as an
16 Cc: <stable@vger.kernel.org>
17 Cc: Vishal Verma <vishal.l.verma@intel.com>
18 Fixes: 37b137ff8c83 ("nfit, libnvdimm: allow an ARS scrub...")
19 Reviewed-by: Dave Jiang <dave.jiang@intel.com>
20 Signed-off-by: Dan Williams <dan.j.williams@intel.com>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 drivers/acpi/nfit/core.c | 5 ++++-
25 1 file changed, 4 insertions(+), 1 deletion(-)
27 --- a/drivers/acpi/nfit/core.c
28 +++ b/drivers/acpi/nfit/core.c
29 @@ -1250,8 +1250,11 @@ static ssize_t scrub_show(struct device
31 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
33 + mutex_lock(&acpi_desc->init_mutex);
34 rc = sprintf(buf, "%d%s", acpi_desc->scrub_count,
35 - (work_busy(&acpi_desc->work)) ? "+\n" : "\n");
36 + work_busy(&acpi_desc->work)
37 + && !acpi_desc->cancel ? "+\n" : "\n");
38 + mutex_unlock(&acpi_desc->init_mutex);