Limit function read to 1 for single function device

Currently the service tries to access functions 0 to 7 for all devices
irrespective of if they are single function or multi function device.
This is not mandatory and and may cause corruption in some single
function devices. Limit the number of functions to check to 1 if the
device is single function device.

Change-Id: I41f088274f3ad8272b2b36e3cb527c61a6c374df
Signed-off-by: Nidhin MS <nidhin.ms@intel.com>
diff --git a/src/peci_pcie.cpp b/src/peci_pcie.cpp
index 32b4e6f..4f1a7eb 100644
--- a/src/peci_pcie.cpp
+++ b/src/peci_pcie.cpp
@@ -589,8 +589,18 @@
         return resCode::resErr;
     }
 
+    bool multiFunc = false;
+    resCode error = isMultiFunction(clientAddr, bus, dev, multiFunc);
+    if (error != resCode::resOk)
+    {
+        return error;
+    }
+    // Functions greater than 0 should only be accessed on multi-function
+    // devices
+    int maxPCIFunctions = multiFunc ? peci_pcie::maxPCIFunctions : 1;
+
     // Walk through and populate the functions for this device
-    for (int func = 0; func < peci_pcie::maxPCIFunctions; func++)
+    for (int func = 0; func < maxPCIFunctions; func++)
     {
         bool res;
         resCode error = pcieFunctionExists(clientAddr, bus, dev, func, res);