aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2018-07-31 10:32:46 -0400
committerDave Jiang <dave.jiang@intel.com>2018-07-31 20:05:42 -0400
commitb7751410c180a05fdc21268f8661b1480169b0df (patch)
treeec5c8bf369681268987df2866ee387e7946d51ca
parentb4d4702f30e09ed1311e560334eb25fc2015c8ce (diff)
device-dax: avoid hang on error before devm_memremap_pages()
dax_pmem_percpu_exit() waits for dax_pmem_percpu_release() to invoke the dax_pmem->cmp completion. Unfortunately this approach to cleaning up the percpu_ref only works after devm_memremap_pages() was successful. If devm_add_action_or_reset() or devm_memremap_pages() fails, dax_pmem_percpu_release() is not invoked. Therefore dax_pmem_percpu_exit() hangs waiting for the completion: rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit, &dax_pmem->ref); if (rc) return rc; dax_pmem->pgmap.ref = &dax_pmem->ref; addr = devm_memremap_pages(dev, &dax_pmem->pgmap); Avoid the hang by calling percpu_ref_exit() in the error paths instead of going through dax_pmem_percpu_exit(). Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
-rw-r--r--drivers/dax/pmem.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index fd49b24fd6af..99e2aace8078 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -105,15 +105,19 @@ static int dax_pmem_probe(struct device *dev)
105 if (rc) 105 if (rc)
106 return rc; 106 return rc;
107 107
108 rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit, 108 rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
109 &dax_pmem->ref); 109 if (rc) {
110 if (rc) 110 percpu_ref_exit(&dax_pmem->ref);
111 return rc; 111 return rc;
112 }
112 113
113 dax_pmem->pgmap.ref = &dax_pmem->ref; 114 dax_pmem->pgmap.ref = &dax_pmem->ref;
114 addr = devm_memremap_pages(dev, &dax_pmem->pgmap); 115 addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
115 if (IS_ERR(addr)) 116 if (IS_ERR(addr)) {
117 devm_remove_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
118 percpu_ref_exit(&dax_pmem->ref);
116 return PTR_ERR(addr); 119 return PTR_ERR(addr);
120 }
117 121
118 rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill, 122 rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill,
119 &dax_pmem->ref); 123 &dax_pmem->ref);