Coverity complained that the 'default' case of the switch in
nodeDeviceGetMdevctlCommand() was falling through without initializing
'cmd'. Return NULL in this case even though it should never happen.
Also, make sure calling functions handle the NULL return consistently.
Some callers already handled it, but some didn't.
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
---
src/node_device/node_device_driver.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index e565cc29ec..c1fe9db149 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -743,7 +743,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def,
case MDEVCTL_CMD_LAST:
default:
/* SHOULD NEVER HAPPEN */
- break;
+ return NULL;
}
switch (cmd_type) {
@@ -931,6 +931,9 @@ virMdevctlStop(virNodeDeviceDef *def, char **errmsg)
cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errmsg);
+ if (!cmd)
+ return -1;
+
if (virCommandRun(cmd, &status) < 0 || status != 0)
return -1;
@@ -946,6 +949,9 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg)
cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, errmsg);
+ if (!cmd)
+ return -1;
+
if (virCommandRun(cmd, &status) < 0 || status != 0)
return -1;
@@ -961,6 +967,9 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg)
cmd = nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errmsg);
+ if (!cmd)
+ return -1;
+
if (virCommandRun(cmd, &status) < 0 || status != 0)
return -1;
--
2.26.3