From: Hannes Reinecke Date: Thu, 3 Feb 2022 11:28:13 +0000 (+0100) Subject: tree: do not set dhchap_key to 'none' X-Git-Tag: v1.0-rc3~13^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fe89efaf32509b416c4519d45b7ac82c88b4a93d;p=users%2Fsagi%2Flibnvme.git tree: do not set dhchap_key to 'none' When no dhchap key is set the kernel will set the sysfs attribute to 'none'. And we shouldn't display this value in our internal tree as it really means 'not set'. Signed-off-by: Hannes Reinecke --- diff --git a/src/nvme/tree.c b/src/nvme/tree.c index 04420bc2..54a33b4b 100644 --- a/src/nvme/tree.c +++ b/src/nvme/tree.c @@ -505,6 +505,10 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name, if (h->dhchap_key) free(h->dhchap_key); h->dhchap_key = nvme_get_attr(path, "dhchap_secret"); + if (h->dhchap_key && !strcmp(h->dhchap_key, "none")) { + free(h->dhchap_key); + h->dhchap_key = NULL; + } } } if (!h) @@ -1106,6 +1110,10 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path, c->serial = nvme_get_ctrl_attr(c, "serial"); c->sqsize = nvme_get_ctrl_attr(c, "sqsize"); c->dhchap_key = nvme_get_ctrl_attr(c, "dhchap_ctrl_secret"); + if (c->dhchap_key && !strcmp(c->dhchap_key, "none")) { + free(c->dhchap_key); + c->dhchap_key = NULL; + } return 0; } @@ -1306,6 +1314,10 @@ nvme_ctrl_t nvme_scan_ctrl(nvme_root_t r, const char *name) if (h->dhchap_key) free(h->dhchap_key); h->dhchap_key = nvme_get_attr(path, "dhchap_secret"); + if (h->dhchap_key && !strcmp(h->dhchap_key, "none")) { + free(h->dhchap_key); + h->dhchap_key = NULL; + } } if (!h) { h = nvme_default_host(r);