A few misc updates. Add the -Wmaybe-uninitialized flag to configure, and
fix the warnings it results in.
Also in update.c, remove a new unnecessary if (cmd) - unref checks as
unref already handles the NULL case.
Vishal Verma (3):
ndctl, inject-smart: cleanup uninitialized variable warnings
ndctl, update: fix uninitialized variable warnings
ndctl, update: remove the check for !cmd when dereferencing it
ndctl/inject-smart.c | 4 ++--
ndctl/update.c | 8 +++-----
2 files changed, 5 insertions(+), 7 deletions(-)
--
2.14.3
Show replies by thread
There were a couple of cases where we could try to unref a command that
had never been initialized. Fix those by always initializing the cmd
pointers to NULL.
Cc: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
ndctl/inject-smart.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ndctl/inject-smart.c b/ndctl/inject-smart.c
index 02f8b0e..45dbc8d 100644
--- a/ndctl/inject-smart.c
+++ b/ndctl/inject-smart.c
@@ -221,7 +221,7 @@ static int smart_init(void)
static int smart_set_thresh(struct ndctl_dimm *dimm)
{
const char *name = ndctl_dimm_get_devname(dimm);
- struct ndctl_cmd *st_cmd, *sst_cmd;
+ struct ndctl_cmd *st_cmd = NULL, *sst_cmd = NULL;
int rc = -EOPNOTSUPP;
st_cmd = ndctl_dimm_cmd_new_smart_threshold(dimm);
@@ -332,7 +332,7 @@ out:
static int smart_inject(struct ndctl_dimm *dimm)
{
const char *name = ndctl_dimm_get_devname(dimm);
- struct ndctl_cmd *si_cmd;
+ struct ndctl_cmd *si_cmd = NULL;
int rc = -EOPNOTSUPP;
send_inject_val(media_temperature)
--
2.14.3
In send_firmware, if the file size ('remain') were to be zero, 'rc'
would never get assigned. While this conditon would never be reached
because we have already checked the file size to be greater than zero,
initialize 'rc' anyway to silence the compiler warning.
Cc: Dan Williams <dan.j.williams(a)intel.com>
Cc: Dave Jiang <dave.jiang(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
ndctl/update.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ndctl/update.c b/ndctl/update.c
index 877d37f..71d95eb 100644
--- a/ndctl/update.c
+++ b/ndctl/update.c
@@ -208,7 +208,7 @@ static int send_firmware(struct update_context *uctx)
{
struct ndctl_cmd *cmd = NULL;
ssize_t read;
- int rc;
+ int rc = -ENXIO;
enum ND_FW_STATUS status;
struct fw_info *fw = &uctx->dimm_fw;
uint32_t copied = 0, len, remain;
--
2.14.3
ndctl_cmd_unref() already checks for the cmd being NULL, no need to
check at every call site.
Cc: Dave Jiang <dave.jiang(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
ndctl/update.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/ndctl/update.c b/ndctl/update.c
index 71d95eb..4ca6a0d 100644
--- a/ndctl/update.c
+++ b/ndctl/update.c
@@ -254,8 +254,7 @@ static int send_firmware(struct update_context *uctx)
}
cleanup:
- if (cmd)
- ndctl_cmd_unref(cmd);
+ ndctl_cmd_unref(cmd);
free(buf);
return rc;
}
@@ -546,8 +545,7 @@ int cmd_update_firmware(int argc, const char **argv, void *ctx)
if (rc < 0)
return rc;
- if (uctx.start)
- ndctl_cmd_unref(uctx.start);
+ ndctl_cmd_unref(uctx.start);
return 0;
}
--
2.14.3
rpmbuild had the above cflag enabled, but local builds didn't, resulting
in missed warnings. Add it to my_CFLAGS in configure.ac
Cc: Dan Williams <dan.j.williams(a)intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma(a)intel.com>
---
configure.ac | 1 +
1 file changed, 1 insertion(+)
diff --git a/configure.ac b/configure.ac
index 70ba360..9067b41 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,6 +145,7 @@ my_CFLAGS="\
-Wsign-compare \
-Wstrict-prototypes \
-Wtype-limits \
+-Wmaybe-uninitialized
"
AC_SUBST([my_CFLAGS])
--
2.14.3