tools/testing/nvdimm: fix nfit_test shutdown crash
authorDan Williams <dan.j.williams@intel.com>
Fri, 14 Apr 2017 06:14:34 +0000 (23:14 -0700)
committerDan Williams <dan.j.williams@intel.com>
Tue, 18 Apr 2017 17:26:09 +0000 (10:26 -0700)
Keep the nfit_test instances alive until after nfit_test_teardown(), as
we may be doing resource lookups until the final un-registrations have
completed. This fixes crashes of the form.

 BUG: unable to handle kernel NULL pointer dereference at 0000000000000038
 IP: __release_resource+0x12/0x90
 Call Trace:
  remove_resource+0x23/0x40
  __wrap_remove_resource+0x29/0x30 [nfit_test_iomap]
  acpi_nfit_remove_resource+0xe/0x10 [nfit]
  devm_action_release+0xf/0x20
  release_nodes+0x16d/0x2b0
  devres_release_all+0x3c/0x60
  device_release+0x21/0x90
  kobject_release+0x6a/0x170
  kobject_put+0x2f/0x60
  put_device+0x17/0x20
  platform_device_unregister+0x20/0x30
  nfit_test_exit+0x36/0x960 [nfit_test]

Reported-by: Linda Knippers <linda.knippers@hpe.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
tools/testing/nvdimm/test/nfit.c

index bc02f28ed8b8e3828b30e05f0a0a5ec7a1834c02..d7fb1b894128a51293aa967695527fa9b4e9c476 100644 (file)
@@ -1958,6 +1958,7 @@ static __init int nfit_test_init(void)
                        put_device(&pdev->dev);
                        goto err_register;
                }
+               get_device(&pdev->dev);
 
                rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
                if (rc)
@@ -1976,6 +1977,10 @@ static __init int nfit_test_init(void)
                if (instances[i])
                        platform_device_unregister(&instances[i]->pdev);
        nfit_test_teardown();
+       for (i = 0; i < NUM_NFITS; i++)
+               if (instances[i])
+                       put_device(&instances[i]->pdev.dev);
+
        return rc;
 }
 
@@ -1983,10 +1988,13 @@ static __exit void nfit_test_exit(void)
 {
        int i;
 
-       platform_driver_unregister(&nfit_test_driver);
        for (i = 0; i < NUM_NFITS; i++)
                platform_device_unregister(&instances[i]->pdev);
+       platform_driver_unregister(&nfit_test_driver);
        nfit_test_teardown();
+
+       for (i = 0; i < NUM_NFITS; i++)
+               put_device(&instances[i]->pdev.dev);
        class_destroy(nfit_test_dimm);
 }