nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: <vishal.l.verma@intel.com>
Cc: linux-nvdimm@lists.01.org, linfeilong <linfeilong@huawei.com>,
	liuzhiqiang26@huawei.com
Subject: [ndctl PATCH 8/8] Check whether seed is NULL in validate_namespace_options
Date: Fri, 6 Nov 2020 17:28:11 +0800	[thread overview]
Message-ID: <685bde1f-1c64-28db-d20d-a0876a7ee76a@huawei.com> (raw)
In-Reply-To: <bed3b3b3-1f30-6751-c0bf-15ecf70192f9@huawei.com>


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 --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.
-- 
1.8.3.1


_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org

  parent reply	other threads:[~2020-11-06  9:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-06  9:23 [ndctl PATCH 0/8] fix serverl issues reported by Coverity Zhiqiang Liu
2020-11-06  9:24 ` [ndctl PATCH 1/8] namespace: check whether pfn|dax|btt is NULL in setup_namespace Zhiqiang Liu
2020-11-20 16:29   ` Jeff Moyer
2020-11-06  9:25 ` [ndctl PATCH 2/8] lib/libndctl: fix memory leakage problem in add_bus Zhiqiang Liu
2020-11-20 16:31   ` Jeff Moyer
2020-11-06  9:25 ` [ndctl PATCH 3/8] libdaxctl: fix memory leakage in add_dax_region() Zhiqiang Liu
2020-11-20 16:33   ` Jeff Moyer
2020-11-06  9:26 ` [ndctl PATCH 4/8] dimm: fix potential fd leakage in dimm_action() Zhiqiang Liu
2020-11-20 16:36   ` Jeff Moyer
2020-11-06  9:26 ` [ndctl PATCH 5/8] util/help: check whether strdup returns NULL in exec_man_konqueror Zhiqiang Liu
2020-11-06  9:27 ` [ndctl PATCH 6/8] lib/inject: check whether cmd is created successfully Zhiqiang Liu
2020-12-17  3:33   ` Verma, Vishal L
2020-12-17  6:19     ` Zhiqiang Liu
2020-11-06  9:27 ` [ndctl PATCH 7/8] Check whether ndctl_btt_get_namespace returns NULL in callers Zhiqiang Liu
2020-11-06  9:28 ` Zhiqiang Liu [this message]
2020-11-10 10:58 ` [ndctl PATCH 0/8] fix serverl issues reported by Coverity Zhiqiang Liu
2020-11-20  2:45 ` Zhiqiang Liu
2020-11-20  2:47   ` Verma, Vishal L
2020-11-20  3:01     ` Zhiqiang Liu
2020-11-20 16:45 ` Jeff Moyer
2020-11-23  0:47   ` Zhiqiang Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=685bde1f-1c64-28db-d20d-a0876a7ee76a@huawei.com \
    --to=liuzhiqiang26@huawei.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).