diff mbox series

[ndctl,1/8] namespace: check whether pfn|dax|btt is NULL in setup_namespace

Message ID 4f51f398-08d0-15c9-fdcb-27b73db78d24@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:24 a.m. UTC
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>
---
 ndctl/namespace.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Jeff Moyer Nov. 20, 2020, 4:29 p.m. UTC | #1
Zhiqiang Liu <liuzhiqiang26@huawei.com> writes:

> 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>
> ---
>  ndctl/namespace.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index e946bb6..257384d 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,7 +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
>  		 * pmem kernel support is pre-v1.2 namespace labels

Minor inconsistency in the last hunk.  The empty line should come after
the return, no?

Other than that, LGTM.

Acked-by: Jeff Moyer <jmoyer@redhat.com>
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index e946bb6..257384d 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,7 +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
 		 * pmem kernel support is pre-v1.2 namespace labels