[libvirt PATCH 2/2] nodedev: handle failure to generate mdevctl cmd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux