Commit b7751410 authored by Stefan Hajnoczi's avatar Stefan Hajnoczi Committed by Dave Jiang

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: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
parent b4d4702f
...@@ -105,15 +105,19 @@ static int dax_pmem_probe(struct device *dev) ...@@ -105,15 +105,19 @@ static int dax_pmem_probe(struct device *dev)
if (rc) if (rc)
return rc; return rc;
rc = devm_add_action_or_reset(dev, dax_pmem_percpu_exit, rc = devm_add_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
&dax_pmem->ref); if (rc) {
if (rc) percpu_ref_exit(&dax_pmem->ref);
return rc; return rc;
}
dax_pmem->pgmap.ref = &dax_pmem->ref; dax_pmem->pgmap.ref = &dax_pmem->ref;
addr = devm_memremap_pages(dev, &dax_pmem->pgmap); addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
if (IS_ERR(addr)) if (IS_ERR(addr)) {
devm_remove_action(dev, dax_pmem_percpu_exit, &dax_pmem->ref);
percpu_ref_exit(&dax_pmem->ref);
return PTR_ERR(addr); return PTR_ERR(addr);
}
rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill, rc = devm_add_action_or_reset(dev, dax_pmem_percpu_kill,
&dax_pmem->ref); &dax_pmem->ref);
......
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