diff mbox series

[ndctl,8/8] Check whether seed is NULL in validate_namespace_options

Message ID 685bde1f-1c64-28db-d20d-a0876a7ee76a@huawei.com (mailing list archive)
State New, archived
Headers show
Series fix serverl issues reported by Coverity | expand

Commit Message

Zhiqiang Liu Nov. 6, 2020, 9:28 a.m. UTC
In validate_namespace_options(), seed is obtained through
calling ndctl_region_get_namespace_seed(), which may return
NULL. If seed is NULL, we should return directly with error
code. In addition, we can use region_name var rather than
calling ndctl_region_get_devname() again.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
 ndctl/namespace.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 257384d..5a92d62 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -847,8 +847,7 @@  static int validate_namespace_options(struct ndctl_region *region,
 	region_align = ndctl_region_get_align(region);
 	if (region_align < ULONG_MAX && p->size % region_align) {
 		err("%s: align setting is %#lx size %#llx is misaligned\n",
-				ndctl_region_get_devname(region), region_align,
-				p->size);
+				region_name, region_align, p->size);
 		return -EINVAL;
 	}

@@ -924,8 +923,13 @@  static int validate_namespace_options(struct ndctl_region *region,
 		} else {
 			struct ndctl_namespace *seed = ndns;

-			if (!seed)
+			if (!seed) {
 				seed = ndctl_region_get_namespace_seed(region);
+				if (!seed) {
+					err("%s: failed to get seed\n", region_name);
+					return -ENXIO;
+				}
+			}
 			num = ndctl_namespace_get_num_sector_sizes(seed);
 			for (i = 0; i < num; i++)
 				if (ndctl_namespace_get_supported_sector_size(seed, i)
@@ -953,9 +957,13 @@  static int validate_namespace_options(struct ndctl_region *region,
 		struct ndctl_namespace *seed;

 		seed = ndctl_region_get_namespace_seed(region);
+		if (!seed) {
+			err("%s: failed to get seed\n", region_name);
+			return -ENXIO;
+		}
 		if (ndctl_namespace_get_type(seed) == ND_DEVICE_NAMESPACE_BLK)
 			debug("%s: set_defaults() should preclude this?\n",
-				ndctl_region_get_devname(region));
+				region_name);
 		/*
 		 * Pick a default sector size for a pmem namespace based
 		 * on what the kernel supports.