src: Fix label logic in virStorageBackendSCSITriggerRescan

Let's initialize @path to NULL, then rather than use two labels
free_path and out labels, let's use the cleanup: label to call
VIR_FREE(path); and VIR_FORCE_CLOSE(fd);

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
John Ferlan 2019-02-11 21:46:28 -05:00
parent 9a4199304f
commit 763b76cbf6
1 changed files with 4 additions and 6 deletions

View File

@ -57,14 +57,14 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
{ {
int fd = -1; int fd = -1;
int retval = 0; int retval = 0;
char *path; char *path = NULL;
VIR_DEBUG("Triggering rescan of host %d", host); VIR_DEBUG("Triggering rescan of host %d", host);
if (virAsprintf(&path, "%s/host%u/scan", if (virAsprintf(&path, "%s/host%u/scan",
LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) { LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0) {
retval = -1; retval = -1;
goto out; goto cleanup;
} }
VIR_DEBUG("Scan trigger path is '%s'", path); VIR_DEBUG("Scan trigger path is '%s'", path);
@ -76,23 +76,21 @@ virStorageBackendSCSITriggerRescan(uint32_t host)
_("Could not open '%s' to trigger host scan"), _("Could not open '%s' to trigger host scan"),
path); path);
retval = -1; retval = -1;
goto free_path; goto cleanup;
} }
if (safewrite(fd, if (safewrite(fd,
LINUX_SYSFS_SCSI_HOST_SCAN_STRING, LINUX_SYSFS_SCSI_HOST_SCAN_STRING,
sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) { sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) {
VIR_FORCE_CLOSE(fd);
virReportSystemError(errno, virReportSystemError(errno,
_("Write to '%s' to trigger host scan failed"), _("Write to '%s' to trigger host scan failed"),
path); path);
retval = -1; retval = -1;
} }
cleanup:
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
free_path:
VIR_FREE(path); VIR_FREE(path);
out:
VIR_DEBUG("Rescan of host %d complete", host); VIR_DEBUG("Rescan of host %d complete", host);
return retval; return retval;
} }