Skip to contentSkip to conversation

dax: Add direct_access() callback check for dax_direct_access()

PATCH In review Dave Jiang 2 participants 2 messages Mar 6 – Mar 9

Subsystems (2)
lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

PATCH 1/1 dax: Add direct_access() callback check for dax_direct_access()

__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().

---
 drivers/dax/super.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dax/super.c +3 -0
index c00b9dff4a06..5cebaf11a58e 100644
@@ -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

Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · Dave Jiang

__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().

Doesn't this need checking in dax_zero_page_range() and dax_recovery_write() as well?

Ira

Quoted 26 lines
---
 drivers/dax/super.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/dax/super.c +3 -0
index c00b9dff4a06..5cebaf11a58e 100644
@@ -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

Signature · 1 line
2.53.0