On Fri, Feb 08, 2019 at 01:37:17PM -0500, John Ferlan wrote:
Modify code to use the VIR_AUTOCLOSE logic cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> Reviewed-by: Erik Skultety <eskultet@xxxxxxxxxx> --- src/storage/storage_backend_logical.c | 3 +- src/storage/storage_backend_scsi.c | 12 +-- src/storage/storage_file_fs.c | 15 +-- src/storage/storage_util.c | 150 ++++++++++---------------- src/util/virstoragefile.c | 39 +++---- 5 files changed, 77 insertions(+), 142 deletions(-)
@@ -1751,17 +1732,17 @@ storageBackendUpdateVolTargetInfo(virStorageVolType voltype, unsigned int openflags, unsigned int readflags) { - int ret, fd = -1; + int ret;
Usually we use 'ret' for the values that will eventually be returned by the function. For storing the values of functions we call, I suggest using 'rc'.
struct stat sb; ssize_t len = VIR_STORAGE_MAX_HEADER; VIR_AUTOFREE(char *) buf = NULL; + VIR_AUTOCLOSE fd = -1; - if ((ret = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0) - goto cleanup;
Before, we propagated the return value of virStorageBackendVolOpen on failure.
- fd = ret; + if ((fd = virStorageBackendVolOpen(target->path, &sb, openflags)) < 0) + return -1;
Now it's always -1.
if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0) - goto cleanup; + return ret; if ((voltype == VIR_STORAGE_VOL_FILE || voltype == VIR_STORAGE_VOL_BLOCK) && target->format != VIR_STORAGE_FILE_NONE) {
storageBackendUpdateVolTargetInfo could use a preparatory patch that will make all the changes here: - ret = %s - goto cleanup + return %s; To the rest: Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> Jano
Attachment:
signature.asc
Description: PGP signature