Fix the bugs found in static analysis

This commit fixes the following static analyzer reported issues:

Operands don't affect result
    some conditions are not required to check as its always true
Unsigned compared against 0
Unchecked return value from library
Uninitialized scalar variable

Change-Id: I0b1fd426794bb88f6eafcc817cef5dd2f655e1ba
Signed-off-by: PavanKumarIntel <pavanx.kumar.martha@intel.com>
diff --git a/apphandler.cpp b/apphandler.cpp
index 7b7bc81..62b17a0 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -94,9 +94,7 @@
 static constexpr const char* cmdMaskStr = "commandMask";
 static constexpr int base_16 = 16;
 #endif // ENABLE_I2C_WHITELIST_CHECK
-static constexpr uint8_t maxIPMIWriteReadSize = 255;
 static constexpr uint8_t oemCmdStart = 192;
-static constexpr uint8_t oemCmdEnd = 255;
 static constexpr uint8_t invalidParamSelectorStart = 8;
 static constexpr uint8_t invalidParamSelectorEnd = 191;
 
@@ -1360,7 +1358,7 @@
     {
         return ipmi::responseInvalidFieldRequest();
     }
-    if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd))
+    if (paramSelector >= oemCmdStart)
     {
         return ipmi::responseParmNotSupported();
     }
@@ -1437,7 +1435,7 @@
     {
         return ipmi::responseInvalidFieldRequest();
     }
-    if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd))
+    if (paramSelector >= oemCmdStart)
     {
         return ipmi::responseParmNotSupported();
     }
@@ -1702,11 +1700,6 @@
     {
         return ipmi::responseInvalidFieldRequest();
     }
-    if (readCount > maxIPMIWriteReadSize)
-    {
-        log<level::ERR>("Master write read command: Read count exceeds limit");
-        return ipmi::responseParmOutOfRange();
-    }
     const size_t writeCount = writeData.size();
     if (!readCount && !writeCount)
     {
diff --git a/transporthandler.cpp b/transporthandler.cpp
index a9bc7c8..59d5f15 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -62,7 +62,6 @@
 };
 
 static constexpr uint8_t oemCmdStart = 192;
-static constexpr uint8_t oemCmdEnd = 255;
 
 // Checks if the ifname is part of the networkd path
 // This assumes the path came from the network subtree PATH_ROOT
@@ -1051,7 +1050,7 @@
         }
     }
 
-    if ((parameter >= oemCmdStart) && (parameter <= oemCmdEnd))
+    if (parameter >= oemCmdStart)
     {
         return setLanOem(channel, parameter, req);
     }
@@ -1354,7 +1353,7 @@
         }
     }
 
-    if ((parameter >= oemCmdStart) && (parameter <= oemCmdEnd))
+    if (parameter >= oemCmdStart)
     {
         return getLanOem(channel, parameter, set, block);
     }
diff --git a/user_channel/channel_layer.cpp b/user_channel/channel_layer.cpp
index fb70f1e..85c3426 100644
--- a/user_channel/channel_layer.cpp
+++ b/user_channel/channel_layer.cpp
@@ -51,9 +51,7 @@
 
 bool isValidAccessMode(const uint8_t accessMode)
 {
-    return (
-        (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
-        (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
+    return (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared));
 }
 
 bool isValidChannel(const uint8_t chNum)
diff --git a/user_channel/channelcommands.cpp b/user_channel/channelcommands.cpp
index e860506..cd0a33b 100644
--- a/user_channel/channelcommands.cpp
+++ b/user_channel/channelcommands.cpp
@@ -195,7 +195,7 @@
         return response(ccActionNotSupportedForChannel);
     }
 
-    ChannelAccess chAccess;
+    ChannelAccess chAccess = {};
 
     Cc compCode = ipmi::ccUnspecifiedError;
 
diff --git a/user_channel/passwd_mgr.cpp b/user_channel/passwd_mgr.cpp
index 7b5b7ec..acf7c74 100644
--- a/user_channel/passwd_mgr.cpp
+++ b/user_channel/passwd_mgr.cpp
@@ -75,7 +75,10 @@
     {
         if ((st.st_mode & modeMask) != (S_IRUSR | S_IWUSR))
         {
-            chmod(passwdFileName, S_IRUSR | S_IWUSR);
+            if (chmod(passwdFileName, S_IRUSR | S_IWUSR) == -1)
+            {
+                log<level::DEBUG>("Error setting chmod for ipmi_pass file");
+            }
         }
     }
 
@@ -83,7 +86,10 @@
     {
         if ((st.st_mode & modeMask) != (S_IRUSR | S_IWUSR))
         {
-            chmod(encryptKeyFileName, S_IRUSR | S_IWUSR);
+            if (chmod(encryptKeyFileName, S_IRUSR | S_IWUSR) == -1)
+            {
+                log<level::DEBUG>("Error setting chmod for ipmi_pass file");
+            }
         }
     }
 }