All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: "Verma, Vishal L" <vishal.l.verma@intel.com>
Cc: "linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>,
	linfeilong <linfeilong@huawei.com>,
	liuzhiqiang26@huawei.com
Subject: [ndctl PATCH V2 1/8] namespace: check whether pfn|dax|btt is NULL in setup_namespace
Date: Wed, 25 Nov 2020 09:01:33 +0800	[thread overview]
Message-ID: <3be32880-1dc3-59ae-3d86-4dc16109b805@huawei.com> (raw)
In-Reply-To: <3211fe8a-33fb-37ca-e192-ad1f116f4acd@huawei.com>


In setup_namespace(), pfn|dax|btt is obtained by calling
ndctl_region_get_**_seed(), which may return NULL. So we
need to check whether pfn|dax|btt is NULL before accessing
them.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
---
 ndctl/namespace.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index e946bb6..631ebdc 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -549,6 +549,8 @@ static int setup_namespace(struct ndctl_region *region,

 	if (do_setup_pfn(ndns, p)) {
 		struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region);
+		if (!pfn)
+			return -ENXIO;

 		rc = check_dax_align(ndns);
 		if (rc)
@@ -563,6 +565,8 @@ static int setup_namespace(struct ndctl_region *region,
 			ndctl_pfn_set_namespace(pfn, NULL);
 	} else if (p->mode == NDCTL_NS_MODE_DEVDAX) {
 		struct ndctl_dax *dax = ndctl_region_get_dax_seed(region);
+		if (!dax)
+			return -ENXIO;

 		rc = check_dax_align(ndns);
 		if (rc)
@@ -577,6 +581,8 @@ static int setup_namespace(struct ndctl_region *region,
 			ndctl_dax_set_namespace(dax, NULL);
 	} else if (p->mode == NDCTL_NS_MODE_SECTOR) {
 		struct ndctl_btt *btt = ndctl_region_get_btt_seed(region);
+		if (!btt)
+			return -ENXIO;

 		/*
 		 * Handle the case of btt on a pmem namespace where the
-- 
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

  reply	other threads:[~2020-11-25  1:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25  1:00 [ndctl PATCH V2 0/8] fix serverl issues reported by Coverity Zhiqiang Liu
2020-11-25  1:01 ` Zhiqiang Liu [this message]
2020-12-09  0:20 ` Jane Chu
2020-12-17  8:18   ` Dan Williams
2020-12-17  3:41 ` Verma, Vishal L
2020-12-17  6:18   ` 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=3be32880-1dc3-59ae-3d86-4dc16109b805@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.