Commit 58cd71b4 authored by Dan Williams's avatar Dan Williams

nfit, tools/testing/nvdimm/: unify shutdown paths

While testing the new on-demand ARS patches we discovered that
differences between the nfit_test and normal nfit driver shutdown paths
can leak resources.  Unify the shutdown paths to trigger via a devm_
callback when the acpi_desc->dev is unbound from its driver.
Reviewed-by: default avatarLee, Chun-Yi <jlee@suse.com>
Reported-by: default avatarVishal Verma <vishal.l.verma@intel.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent bc9775d8
...@@ -2291,6 +2291,16 @@ static int acpi_nfit_check_deletions(struct acpi_nfit_desc *acpi_desc, ...@@ -2291,6 +2291,16 @@ static int acpi_nfit_check_deletions(struct acpi_nfit_desc *acpi_desc,
return 0; return 0;
} }
static void acpi_nfit_destruct(void *data)
{
struct acpi_nfit_desc *acpi_desc = data;
acpi_desc->cancel = 1;
flush_workqueue(nfit_wq);
nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
acpi_desc->nvdimm_bus = NULL;
}
int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz) int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz)
{ {
struct device *dev = acpi_desc->dev; struct device *dev = acpi_desc->dev;
...@@ -2298,6 +2308,17 @@ int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz) ...@@ -2298,6 +2308,17 @@ int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *data, acpi_size sz)
const void *end; const void *end;
int rc; int rc;
if (!acpi_desc->nvdimm_bus) {
acpi_desc->nvdimm_bus = nvdimm_bus_register(dev,
&acpi_desc->nd_desc);
if (!acpi_desc->nvdimm_bus)
return -ENOMEM;
rc = devm_add_action_or_reset(dev, acpi_nfit_destruct,
acpi_desc);
if (rc)
return rc;
}
mutex_lock(&acpi_desc->init_mutex); mutex_lock(&acpi_desc->init_mutex);
INIT_LIST_HEAD(&prev.spas); INIT_LIST_HEAD(&prev.spas);
...@@ -2456,9 +2477,6 @@ static int acpi_nfit_add(struct acpi_device *adev) ...@@ -2456,9 +2477,6 @@ static int acpi_nfit_add(struct acpi_device *adev)
if (!acpi_desc) if (!acpi_desc)
return -ENOMEM; return -ENOMEM;
acpi_nfit_desc_init(acpi_desc, &adev->dev); acpi_nfit_desc_init(acpi_desc, &adev->dev);
acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc);
if (!acpi_desc->nvdimm_bus)
return -ENOMEM;
/* Save the acpi header for exporting the revision via sysfs */ /* Save the acpi header for exporting the revision via sysfs */
acpi_desc->acpi_header = *tbl; acpi_desc->acpi_header = *tbl;
...@@ -2480,19 +2498,12 @@ static int acpi_nfit_add(struct acpi_device *adev) ...@@ -2480,19 +2498,12 @@ static int acpi_nfit_add(struct acpi_device *adev)
rc = acpi_nfit_init(acpi_desc, (void *) tbl rc = acpi_nfit_init(acpi_desc, (void *) tbl
+ sizeof(struct acpi_table_nfit), + sizeof(struct acpi_table_nfit),
sz - sizeof(struct acpi_table_nfit)); sz - sizeof(struct acpi_table_nfit));
if (rc)
nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
return rc; return rc;
} }
static int acpi_nfit_remove(struct acpi_device *adev) static int acpi_nfit_remove(struct acpi_device *adev)
{ {
struct acpi_nfit_desc *acpi_desc = dev_get_drvdata(&adev->dev); /* see acpi_nfit_destruct */
acpi_desc->cancel = 1;
flush_workqueue(nfit_wq);
nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
return 0; return 0;
} }
...@@ -2519,9 +2530,6 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event) ...@@ -2519,9 +2530,6 @@ static void acpi_nfit_notify(struct acpi_device *adev, u32 event)
if (!acpi_desc) if (!acpi_desc)
goto out_unlock; goto out_unlock;
acpi_nfit_desc_init(acpi_desc, &adev->dev); acpi_nfit_desc_init(acpi_desc, &adev->dev);
acpi_desc->nvdimm_bus = nvdimm_bus_register(dev, &acpi_desc->nd_desc);
if (!acpi_desc->nvdimm_bus)
goto out_unlock;
} else { } else {
/* /*
* Finish previous registration before considering new * Finish previous registration before considering new
......
...@@ -1465,16 +1465,11 @@ static int nfit_test_probe(struct platform_device *pdev) ...@@ -1465,16 +1465,11 @@ static int nfit_test_probe(struct platform_device *pdev)
nd_desc->provider_name = NULL; nd_desc->provider_name = NULL;
nd_desc->module = THIS_MODULE; nd_desc->module = THIS_MODULE;
nd_desc->ndctl = nfit_test_ctl; nd_desc->ndctl = nfit_test_ctl;
acpi_desc->nvdimm_bus = nvdimm_bus_register(&pdev->dev, nd_desc);
if (!acpi_desc->nvdimm_bus)
return -ENXIO;
rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf,
nfit_test->nfit_size); nfit_test->nfit_size);
if (rc) { if (rc)
nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
return rc; return rc;
}
if (nfit_test->setup != nfit_test0_setup) if (nfit_test->setup != nfit_test0_setup)
return 0; return 0;
...@@ -1484,21 +1479,14 @@ static int nfit_test_probe(struct platform_device *pdev) ...@@ -1484,21 +1479,14 @@ static int nfit_test_probe(struct platform_device *pdev)
rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf, rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf,
nfit_test->nfit_size); nfit_test->nfit_size);
if (rc) { if (rc)
nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
return rc; return rc;
}
return 0; return 0;
} }
static int nfit_test_remove(struct platform_device *pdev) static int nfit_test_remove(struct platform_device *pdev)
{ {
struct nfit_test *nfit_test = to_nfit_test(&pdev->dev);
struct acpi_nfit_desc *acpi_desc = &nfit_test->acpi_desc;
nvdimm_bus_unregister(acpi_desc->nvdimm_bus);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment