From ca3193cf4d2a756512007d2c23202d6844e1840d Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Fri, 29 Dec 2023 18:37:41 +0100
Subject: [PATCH 1/4] fabrics: Explicitly initialize auto-cleanup variables
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
gcc complains about potentially uninitialized variables used
in the cleanup function even though such scenario is unlikely
to happen. Still, an explicit initializer makes the warnings
go away.
E.g.
../src/nvme/fabrics.c: In function ‘nvmf_hostnqn_generate’:
../src/nvme/fabrics.c:1297:30: note: ‘stream’ was declared here
1297 | _cleanup_file_ FILE *stream;
| ^~~~~~
In function ‘cleanup_fd’,
inlined from ‘uuid_from_device_tree’ at ../src/nvme/fabrics.c:1189:19,
inlined from ‘nvmf_hostnqn_generate’ at ../src/nvme/fabrics.c:1350:9:
../src/nvme/cleanup.h:37:17: warning: ‘f’ may be used uninitialized [-Wmaybe-uninitialized]
37 | close(*fd);
| ^~~~~~~~~~
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
src/nvme/fabrics.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
index 4e042d84..20142116 100644
--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -740,7 +740,7 @@ static int __nvmf_supported_options(nvme_root_t r)
static int __nvmf_add_ctrl(nvme_root_t r, const char *argstr)
{
- _cleanup_fd_ int fd;
+ _cleanup_fd_ int fd = -1;
int ret, len = strlen(argstr);
char buf[0x1000], *options, *p;
@@ -1186,7 +1186,7 @@ struct nvmf_discovery_log *nvmf_get_discovery_wargs(struct nvme_get_discovery_ar
static int uuid_from_device_tree(char *system_uuid)
{
ssize_t len;
- _cleanup_fd_ int f;
+ _cleanup_fd_ int f = -1;
f = open(PATH_UUID_IBM, O_RDONLY);
if (f < 0)
@@ -1230,7 +1230,7 @@ static bool is_dmi_uuid_valid(const char *buf, size_t len)
static int uuid_from_dmi_entries(char *system_uuid)
{
int f;
- _cleanup_dir_ DIR *d;
+ _cleanup_dir_ DIR *d = NULL;
struct dirent *de;
char buf[512] = {0};
@@ -1294,7 +1294,7 @@ static int uuid_from_dmi_entries(char *system_uuid)
*/
static int uuid_from_product_uuid(char *system_uuid)
{
- _cleanup_file_ FILE *stream;
+ _cleanup_file_ FILE *stream = NULL;
ssize_t nread;
_cleanup_free_ char *line = NULL;
size_t len = 0;
@@ -1364,7 +1364,7 @@ char *nvmf_hostnqn_generate()
static char *nvmf_read_file(const char *f, int len)
{
char buf[len];
- _cleanup_fd_ int fd;
+ _cleanup_fd_ int fd = -1;
int ret;
fd = open(f, O_RDONLY);
@@ -1637,7 +1637,7 @@ static const char *dctype_str[] = {
*/
static int nvme_fetch_cntrltype_dctype_from_id(nvme_ctrl_t c)
{
- _cleanup_free_ struct nvme_id_ctrl *id;
+ _cleanup_free_ struct nvme_id_ctrl *id = NULL;
int ret;
id = __nvme_alloc(sizeof(*id));
From fdb6415f5e9f7a18380633a1c797aca00d9daccb Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Fri, 29 Dec 2023 18:49:25 +0100
Subject: [PATCH 2/4] linux: Explicitly initialize auto-cleanup variables
gcc complains about potentially uninitialized variables.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
src/nvme/linux.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/nvme/linux.c b/src/nvme/linux.c
index 163086ea..074c27e0 100644
--- a/src/nvme/linux.c
+++ b/src/nvme/linux.c
@@ -124,7 +124,7 @@ int nvme_fw_download_seq(int fd, __u32 size, __u32 xfer, __u32 offset,
int nvme_get_telemetry_max(int fd, enum nvme_telemetry_da *da, size_t *data_tx)
{
- _cleanup_free_ struct nvme_id_ctrl *id_ctrl;
+ _cleanup_free_ struct nvme_id_ctrl *id_ctrl = NULL;
int err;
id_ctrl = __nvme_alloc(sizeof(*id_ctrl));
@@ -385,7 +385,7 @@ int nvme_namespace_detach_ctrls(int fd, __u32 nsid, __u16 num_ctrls,
int nvme_get_ana_log_len(int fd, size_t *analen)
{
- _cleanup_free_ struct nvme_id_ctrl *ctrl;
+ _cleanup_free_ struct nvme_id_ctrl *ctrl = NULL;
int ret;
ctrl = __nvme_alloc(sizeof(*ctrl));
@@ -405,7 +405,7 @@ int nvme_get_ana_log_len(int fd, size_t *analen)
int nvme_get_logical_block_size(int fd, __u32 nsid, int *blksize)
{
- _cleanup_free_ struct nvme_id_ns *ns;
+ _cleanup_free_ struct nvme_id_ns *ns = NULL;
__u8 flbas;
int ret;
@@ -426,7 +426,7 @@ int nvme_get_logical_block_size(int fd, __u32 nsid, int *blksize)
static int __nvme_set_attr(const char *path, const char *value)
{
- _cleanup_fd_ int fd;
+ _cleanup_fd_ int fd = -1;
fd = open(path, O_WRONLY);
if (fd < 0) {
From 533edeb32027c43895c878149117173bba785dff Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Fri, 29 Dec 2023 18:49:36 +0100
Subject: [PATCH 3/4] tree: Explicitly initialize auto-cleanup variables
gcc complains about potentially uninitialized variables.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
src/nvme/tree.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/nvme/tree.c b/src/nvme/tree.c
index 07a3c532..97bd3ef4 100644
--- a/src/nvme/tree.c
+++ b/src/nvme/tree.c
@@ -122,7 +122,8 @@ static void cleanup_dirents(struct dirents *ents)
nvme_host_t nvme_default_host(nvme_root_t r)
{
struct nvme_host *h;
- _cleanup_free_ char *hostnqn, *hostid;
+ _cleanup_free_ char *hostnqn = NULL;
+ _cleanup_free_ char *hostid = NULL;
hostnqn = nvmf_hostnqn_from_file();
if (!hostnqn)
@@ -1853,7 +1854,7 @@ static nvme_ctrl_t nvme_ctrl_alloc(nvme_root_t r, nvme_subsystem_t s,
nvme_ctrl_t c, p;
_cleanup_free_ char *addr = NULL, *address = NULL;
char *a, *e;
- _cleanup_free_ char *transport;
+ _cleanup_free_ char *transport = NULL;
char *traddr = NULL, *trsvcid = NULL;
char *host_traddr = NULL, *host_iface = NULL;
int ret;
From aa072f89c8a163780250fa1a2dd507de6b45ab49 Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Fri, 29 Dec 2023 18:49:44 +0100
Subject: [PATCH 4/4] util: Explicitly initialize auto-cleanup variables
gcc complains about potentially uninitialized variables.
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
---
src/nvme/util.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/nvme/util.c b/src/nvme/util.c
index 45512ff9..3861c1ab 100644
--- a/src/nvme/util.c
+++ b/src/nvme/util.c
@@ -757,7 +757,7 @@ char *kv_keymatch(const char *kv, const char *key)
static size_t read_file(const char * fname, char *buffer, size_t *bufsz)
{
char *p;
- _cleanup_file_ FILE *file;
+ _cleanup_file_ FILE *file = NULL;
size_t len;
file = fopen(fname, "re");
@@ -806,7 +806,7 @@ size_t get_entity_name(char *buffer, size_t bufsz)
size_t get_entity_version(char *buffer, size_t bufsz)
{
- _cleanup_file_ FILE *file;
+ _cleanup_file_ FILE *file = NULL;
size_t num_bytes = 0;
/* /proc/sys/kernel/ostype typically contains the string "Linux" */
@@ -928,7 +928,7 @@ int nvme_uuid_from_string(const char *str, unsigned char uuid[NVME_UUID_LEN])
int nvme_uuid_random(unsigned char uuid[NVME_UUID_LEN])
{
- _cleanup_fd_ int f;
+ _cleanup_fd_ int f = -1;
ssize_t n;
f = open("/dev/urandom", O_RDONLY);