[v3,4/6] libnvdimm/namespace: Add debug check while initializing namespace resource size.
diff mbox series

Message ID 20200108065219.171221-4-aneesh.kumar@linux.ibm.com
State New
Headers show
Series
  • [v3,1/6] libnvdimm/namespace: Make namespace size validation arch dependent
Related show

Commit Message

Aneesh Kumar K.V Jan. 8, 2020, 6:52 a.m. UTC
This should enable us to catch if we are initializing the namespace with a wrong
size.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
---
 drivers/nvdimm/namespace_devs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch
diff mbox series

diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
index 8567d8969014..99e6140bb19d 100644
--- a/drivers/nvdimm/namespace_devs.c
+++ b/drivers/nvdimm/namespace_devs.c
@@ -941,6 +941,18 @@  static void nd_namespace_pmem_set_resource(struct nd_region *nd_region,
  out:
 	res->start = nd_region->ndr_start + offset;
 	res->end = res->start + size - 1;
+#ifdef CONFIG_DEBUG_VM
+	if (size) {
+		unsigned long map_size;
+
+		map_size = nvdimm_validate_namespace_size(nd_region, size, arch_namespace_align_size());
+		WARN_ON(map_size);
+
+		map_size = nvdimm_validate_namespace_size(nd_region, res->start, arch_namespace_align_size());
+		WARN_ON(map_size);
+
+	}
+#endif
 }
 
 static bool uuid_not_set(const u8 *uuid, struct device *dev, const char *where)