When a region is disabled, there is no driver attached. Therefore
dev->driverdata is NULL. An attempt to write to regionN/deep_flush via sysfs
would cause a NULL pointer dereference. Bail when dev->driver is NULL to
protect this scenario.

Fix: ab630891ce0eb(libnvdimm, region: sysfs trigger for nvdimm_flush())

Signed-off-by: Dave Jiang <dave.ji...@intel.com>
---

v2: Move to deep_flush_store. (Dan)

 drivers/nvdimm/region_devs.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index a612be6f019d..65cc2a5b48b8 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -290,6 +290,11 @@ static ssize_t deep_flush_store(struct device *dev, struct 
device_attribute *att
                return rc;
        if (!flush)
                return -EINVAL;
+
+       /* protect against disabled region */
+       if (!nd_region->dev.driver)
+               return -ENXIO;
+
        nvdimm_flush(nd_region);
 
        return len;

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reply via email to