summaryrefslogtreecommitdiffstats
path: root/nvme-models.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--nvme-models.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/nvme-models.c b/nvme-models.c
index 8fd8152..f638e4d 100644
--- a/nvme-models.c
+++ b/nvme-models.c
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -59,10 +60,13 @@ static char *find_data(char *data)
static char *locate_info(char *data, bool is_inner, bool is_class)
{
char *orig = data;
- char *locate = find_data(data);
+ char *locate;
if (!data)
return orig;
+ locate = find_data(data);
+ if (!locate)
+ return orig;
if (is_class)
return locate + 4;
if (!is_inner)
@@ -236,7 +240,7 @@ static void pull_class_info(char **_newline, FILE *file, char *class)
static int read_sys_node(char *where, char *save, size_t savesz)
{
char *new;
- int fd, ret = 0;
+ int fd, ret = 0, len;
fd = open(where, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Failed to open %s with errno %s\n",
@@ -244,13 +248,15 @@ static int read_sys_node(char *where, char *save, size_t savesz)
return 1;
}
/* -1 so we can safely use strstr below */
- if(!read(fd, save, savesz - 1))
+ len = read(fd, save, savesz - 1);
+ if (!len)
ret = 1;
-
- new = strstr(save, "\n");
- if (new)
- new[0] = '\0';
-
+ else {
+ save[len] = '\0';
+ new = strstr(save, "\n");
+ if (new)
+ new[0] = '\0';
+ }
close(fd);
return ret;
}
@@ -330,6 +336,7 @@ char *nvme_product_name(int id)
continue;
if (is_top_level_match(line, vendor, false)) {
line[amnt - 1] = '\0';
+ free(device_top);
device_top = strdup(line);
parse_vendor_device(&line, file,
device,
@@ -346,5 +353,5 @@ char *nvme_product_name(int id)
error0:
fclose(file);
error1:
- return !line ? strdup("NULL") : strdup("Unknown Device");
+ return strdup("NULL");
}