Refactor driver version handling in GPUSWInventory

Changes:
- Updated driverVersion to use std::string for better memory
  management.
- Adjusted error handling to set previous driver version on
  failure.
- Improved state change detection and logging for driver state
  updates.

Tested enabling/disabling persistence mode on all 8 GPUs using
nvidia-smi on umb-emr-410. Verified driver state transitions through
Redfish API on HMC; all GPUs correctly reported Enabled or Disabled
after each state change. Repeated the enable cycle again to confirm
stability and consistent reporting.

Fixes nvbug https://nvbugspro.nvidia.com/bug/5351720
Signed-off-by: Paweł Iwaneczko <piwaneczko@nvidia.com>
diff --git a/nsmd/nsmFwSwInventory/GPUSWInventory.cpp b/nsmd/nsmFwSwInventory/GPUSWInventory.cpp
index 5a1914a..8966481 100644
--- a/nsmd/nsmFwSwInventory/GPUSWInventory.cpp
+++ b/nsmd/nsmFwSwInventory/GPUSWInventory.cpp
@@ -90,29 +90,33 @@
     uint8_t cc = NSM_ERROR;
     uint16_t reasonCode = ERR_NULL;
     enum8 driverState = 0;
-    char driverVersion[MAX_VERSION_STRING_SIZE] = {0};
+    std::string driverVersion("", MAX_VERSION_STRING_SIZE);
 
     rc = decode_get_driver_info_resp(responseMsg.get(), responseLen, &cc,
-                                     &reasonCode, &driverState, driverVersion);
+                                     &reasonCode, &driverState,
+                                     (char*)driverVersion.data());
 
     LG2_ERROR_FLT(
         "decode_get_driver_info_resp failure | reasonCode: {REASONCODE}, cc: {CC}, rc: {RC}",
         "REASONCODE", reasonCode, "CC", cc, "RC", rc);
-    if (rc == NSM_SW_SUCCESS && cc == NSM_SUCCESS)
+    if (rc != NSM_SW_SUCCESS || cc != NSM_SUCCESS)
     {
-        std::string version(driverVersion);
-        // Check if the values have changed
-        bool stateChanged = (this->driverState != driverState);
-        updateValue(driverState, version);
-        if (stateChanged)
-        {
-            lg2::info(
-                "NsmGPUSWInventoryDriverVersionAndStatus: state changed eid={EID}",
-                "EID", eid);
-            DeviceManager& deviceManager = DeviceManager::getInstance();
-            co_await deviceManager.updateNsmDevice(nsmDeviceFound, eid);
-        }
+        // Set previous version on error;
+        driverVersion = this->driverVersion;
     }
+
+    // Check if the values have changed
+    bool stateChanged = (this->driverState != driverState);
+    updateValue(driverState, driverVersion);
+    if (stateChanged)
+    {
+        lg2::info(
+            "NsmGPUSWInventoryDriverVersionAndStatus: state changed eid={EID}",
+            "EID", eid);
+        DeviceManager& deviceManager = DeviceManager::getInstance();
+        co_await deviceManager.updateNsmDevice(nsmDeviceFound, eid);
+    }
+
     // coverity[missing_return]
     co_return cc ? cc : rc;
 }