]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
src/nvme/tree.c: make __nvme_scan_subsystem() returning bool
authorHannes Reinecke <hare@suse.de>
Tue, 8 Aug 2023 11:32:53 +0000 (13:32 +0200)
committerDaniel Wagner <wagi@monom.org>
Tue, 8 Aug 2023 12:39:04 +0000 (14:39 +0200)
__nvme_scan_subsystem() will free the 's' argument when the filter
triggers, so it needs a return value to inform the caller that the
argument has been freed.

Signed-off-by: Hannes Reinecke <hare@suse.de>
src/nvme/tree.c

index 6594136ab99db6657ba81761ff7f059f58d2cfed..208e7caa8034011c3929b6415f24a6afd02b1cab 100644 (file)
@@ -650,15 +650,16 @@ static int nvme_init_subsystem(nvme_subsystem_t s, const char *name)
        return 0;
 }
 
-static void __nvme_scan_subsystem(struct nvme_root *r, nvme_subsystem_t s,
+static bool __nvme_scan_subsystem(struct nvme_root *r, nvme_subsystem_t s,
                                  nvme_scan_filter_t f, void *f_args)
 {
        if (f && !f(s, NULL, NULL, f_args)) {
                nvme_msg(r, LOG_DEBUG, "filter out subsystem %s\n", s->name);
                __nvme_free_subsystem(s);
-               return;
+               return false;
        }
        nvme_subsystem_scan_namespaces(r, s, f, f_args);
+       return true;
 }
 
 static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
@@ -691,8 +692,11 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
                                continue;
                        if (strcmp(_s->name, name))
                                continue;
+                       if (!__nvme_scan_subsystem(r, s, f, f_args)) {
+                               errno = -EINVAL;
+                               goto out_free;
+                       }
                        s = _s;
-                       __nvme_scan_subsystem(r, s, f, f_args);
                }
        }
        if (!s) {
@@ -705,16 +709,20 @@ static int nvme_scan_subsystem(struct nvme_root *r, const char *name,
                         name);
                h = nvme_default_host(r);
                s = nvme_alloc_subsystem(h, name, subsysnqn);
-               if (s)
-                       __nvme_scan_subsystem(r, s, f, f_args);
-               else
+               if (!s) {
                        ret = -ENOMEM;
+                       goto out_free;
+               }
+               if (!__nvme_scan_subsystem(r, s, f, f_args)) {
+                       ret = -EINVAL;
+                       goto out_free;
+               }
        } else if (strcmp(s->subsysnqn, subsysnqn)) {
                nvme_msg(r, LOG_DEBUG, "NQN mismatch for subsystem '%s'\n",
                         name);
                ret = -EINVAL;
        }
-
+out_free:
        free(subsysnqn);
 
        if (ret) {