1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

getNewStyleBlockDevice: Adjust formatting

Instead of initializing return value to zero (success) and overwriting
it on every failure just before the control jumps onto 'out' label,
let's initialize to an error value and set to zero only when we are
sure about the success. Just follow the pattern we have in the rest of
the code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-06-15 13:13:27 +02:00
parent 84020f9a39
commit 71b66bec2b

View File

@ -255,44 +255,41 @@ getNewStyleBlockDevice(const char *lun_path,
char *block_path = NULL; char *block_path = NULL;
DIR *block_dir = NULL; DIR *block_dir = NULL;
struct dirent *block_dirent = NULL; struct dirent *block_dirent = NULL;
int retval = 0; int retval = -1;
int direrr; int direrr;
if (virAsprintf(&block_path, "%s/block", lun_path) < 0) if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
goto out; goto cleanup;
VIR_DEBUG("Looking for block device in '%s'", block_path); VIR_DEBUG("Looking for block device in '%s'", block_path);
block_dir = opendir(block_path); if (!(block_dir = opendir(block_path))) {
if (block_dir == NULL) {
virReportSystemError(errno, virReportSystemError(errno,
_("Failed to opendir sysfs path '%s'"), _("Failed to opendir sysfs path '%s'"),
block_path); block_path);
retval = -1; goto cleanup;
goto out;
} }
while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) { while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
if (STREQLEN(block_dirent->d_name, ".", 1)) if (STREQLEN(block_dirent->d_name, ".", 1))
continue; continue;
if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0) { if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0)
closedir(block_dir); goto cleanup;
retval = -1;
goto out;
}
VIR_DEBUG("Block device is '%s'", *block_device); VIR_DEBUG("Block device is '%s'", *block_device);
break; break;
} }
if (direrr < 0) if (direrr < 0)
retval = -1; goto cleanup;
closedir(block_dir); retval = 0;
out: cleanup:
if (block_dir)
closedir(block_dir);
VIR_FREE(block_path); VIR_FREE(block_path);
return retval; return retval;
} }