The code did not free 'dir' allocated by opendir(). An additional
benefit is that this simplifies the for() loops.
Fixes: 60f0f54d ("IMSM: Add support for VMD")
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
return NULL;
dir = opendir("/sys/bus/pci/drivers/vmd");
+ if (!dir)
+ return NULL;
- for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+ for (ent = readdir(dir); ent; ent = readdir(dir)) {
sprintf(path, "/sys/bus/pci/drivers/vmd/%s/domain/device",
ent->d_name);
if (strncmp(buf, hba->path, strlen(buf)) == 0) {
sprintf(path, "/sys/bus/pci/drivers/vmd/%s", ent->d_name);
+ closedir(dir);
return realpath(path, buf);
}
}
+
+ closedir(dir);
return NULL;
}
* this hba
*/
dir = opendir("/sys/bus/pci/drivers/nvme");
- for (ent = dir ? readdir(dir) : NULL; ent; ent = readdir(dir)) {
+ if (!dir)
+ return 1;
+
+ for (ent = readdir(dir); ent; ent = readdir(dir)) {
int n;
/* is 'ent' a device? check that the 'subsystem' link exists and
free(rp);
}
+ closedir(dir);
return 0;
}