52 lines
1.3 KiB
Diff
52 lines
1.3 KiB
Diff
From 59e7477c5a18ec4bcb1f9b1e20d2303b4e0cafb1 Mon Sep 17 00:00:00 2001
|
|
From: Martin George <marting@netapp.com>
|
|
Date: Thu, 5 Aug 2021 18:01:24 +0530
|
|
Subject: [PATCH] nvme-print: fix 'nvme list' segfault if controller is
|
|
unavailable
|
|
|
|
Check if the controller is available before dereferencing the
|
|
controller attributes.
|
|
|
|
Signed-off-by: Martin George <marting@netapp.com>
|
|
---
|
|
nvme-print.c | 9 +++++++++
|
|
1 file changed, 9 insertions(+)
|
|
|
|
diff --git a/nvme-print.c b/nvme-print.c
|
|
index 8a2cbc4..0c0ec3b 100755
|
|
--- a/nvme-print.c
|
|
+++ b/nvme-print.c
|
|
@@ -6147,6 +6147,9 @@ static void nvme_show_list_item(struct nvme_namespace *n)
|
|
struct stat st;
|
|
int ret;
|
|
|
|
+ if (!n->ctrl)
|
|
+ return;
|
|
+
|
|
sprintf(path, "%s%s", n->ctrl->path, n->name);
|
|
ret = stat(path, &st);
|
|
if (ret < 0)
|
|
@@ -6203,6 +6206,9 @@ static void nvme_show_details_ns(struct nvme_namespace *n, bool ctrl)
|
|
char usage[128];
|
|
char format[128];
|
|
|
|
+ if (!n->ctrl)
|
|
+ return;
|
|
+
|
|
sprintf(usage,"%6.2f %2sB / %6.2f %2sB", nuse, u_suffix,
|
|
nsze, s_suffix);
|
|
sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix,
|
|
@@ -6419,6 +6425,9 @@ static void json_simple_ns(struct nvme_namespace *n, struct json_object *devices
|
|
char *devnode;
|
|
struct stat st;
|
|
|
|
+ if (!n->ctrl)
|
|
+ return;
|
|
+
|
|
if (asprintf(&devnode, "%s%s", n->ctrl->path, n->name) < 0)
|
|
return;
|
|
|
|
--
|
|
2.27.0
|
|
|