util: mdev: Use a local variable instead of a direct pointer access

Use a local variable to hold data, rather than accessing the pointer
after calling virMediatedDeviceListAdd (therefore VIR_APPEND_ELEMENT).
Although not causing an issue at the moment, this change is a necessary
prerequisite for tweaking virMediatedDeviceListAdd in a separate patch,
which will take a reference for the source pointer (instead of pointer
value) and will clear it along the way.

(cherry picked from commit 2739a983f2)
Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety 2017-04-28 07:52:52 +02:00
parent 04535336a9
commit 5d4ecee94f

View File

@ -447,20 +447,21 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListPtr dst,
virObjectLock(dst); virObjectLock(dst);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
virMediatedDevicePtr mdev = virMediatedDeviceListGet(src, i); virMediatedDevicePtr mdev = virMediatedDeviceListGet(src, i);
const char *mdev_path = mdev->path;
if (virMediatedDeviceIsUsed(mdev, dst) || if (virMediatedDeviceIsUsed(mdev, dst) ||
virMediatedDeviceSetUsedBy(mdev, drvname, domname) < 0) virMediatedDeviceSetUsedBy(mdev, drvname, domname) < 0)
goto cleanup; goto cleanup;
/* Copy mdev references to the driver list: /* Copy mdev references to the driver list:
* - caller is responsible for NOT freeing devices in @list on success * - caller is responsible for NOT freeing devices in @src on success
* - we're responsible for performing a rollback on failure * - we're responsible for performing a rollback on failure
*/ */
if (virMediatedDeviceListAdd(dst, mdev) < 0) if (virMediatedDeviceListAdd(dst, mdev) < 0)
goto rollback; goto rollback;
VIR_DEBUG("'%s' added to list of active mediated devices used by '%s'", VIR_DEBUG("'%s' added to list of active mediated devices used by '%s'",
mdev->path, domname); mdev_path, domname);
} }
ret = 0; ret = 0;