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