__devm_create_dev_dax() calls alloc_dax() with the ops parameter passed
in as NULL. Therefore the ops pointer in dev_dax can be NULL. Add a
check in dax_direct_access() for ops and ops->direct_access() before
calling ops->direct_access().

Signed-off-by: Dave Jiang <[email protected]>
---
 drivers/dax/super.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/dax/super.c b/drivers/dax/super.c
index c00b9dff4a06..5cebaf11a58e 100644
--- a/drivers/dax/super.c
+++ b/drivers/dax/super.c
@@ -160,6 +160,9 @@ long dax_direct_access(struct dax_device *dax_dev, pgoff_t 
pgoff, long nr_pages,
        if (nr_pages < 0)
                return -EINVAL;
 
+       if (!dax_dev->ops || !dax_dev->ops->direct_access)
+               return -EOPNOTSUPP;
+
        avail = dax_dev->ops->direct_access(dax_dev, pgoff, nr_pages,
                        mode, kaddr, pfn);
        if (!avail)

base-commit: 11439c4635edd669ae435eec308f4ab8a0804808
-- 
2.53.0


Reply via email to