From d901fd6092414417ee59a4567d2c62f853a62d5c Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 4 May 2020 17:03:42 +0200 Subject: [PATCH] Drop needless variable Instead of the following pattern: type ret; ... ret = func(); return ret; we can use: return func() directly. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/conf/domain_addr.c | 8 +------- src/conf/domain_conf.c | 8 +++----- src/conf/network_conf.c | 5 +---- src/conf/virnetworkportdef.c | 5 +---- src/qemu/qemu_capabilities.c | 5 +---- src/qemu/qemu_command.c | 8 ++------ src/qemu/qemu_conf.c | 9 ++------- src/qemu/qemu_domain.c | 12 +++--------- src/qemu/qemu_driver.c | 18 ++++++------------ src/qemu/qemu_tpm.c | 11 ++--------- src/security/security_apparmor.c | 5 +---- src/security/security_util.c | 9 +++------ src/storage/storage_driver.c | 7 ++----- src/util/vircgroup.c | 5 +---- src/util/virmdev.c | 10 ++-------- src/util/virresctrl.c | 6 +----- src/util/virsocketaddr.c | 5 +---- src/util/virutil.c | 8 +++----- tests/qemuxml2argvtest.c | 6 +----- 19 files changed, 37 insertions(+), 113 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 5652bc9a33..8623e79daf 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1392,13 +1392,7 @@ virDomainPCIAddressSetAllMulti(virDomainDefPtr def) static char* virDomainCCWAddressAsString(virDomainDeviceCCWAddressPtr addr) { - char *addrstr = NULL; - - addrstr = g_strdup_printf("%x.%x.%04x", - addr->cssid, - addr->ssid, - addr->devno); - return addrstr; + return g_strdup_printf("%x.%x.%04x", addr->cssid, addr->ssid, addr->devno); } static int diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8a87586936..83748354b0 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31317,7 +31317,6 @@ virDomainDefGetShortName(const virDomainDef *def) { wchar_t wshortname[VIR_DOMAIN_SHORT_NAME_MAX + 1] = {0}; size_t len = 0; - char *ret = NULL; g_autofree char *shortname = NULL; /* No need to do the whole conversion thing when there are no multibyte @@ -31326,8 +31325,8 @@ virDomainDefGetShortName(const virDomainDef *def) len = mbstowcs(NULL, def->name, 0); if ((len == (size_t) -1 && errno == EILSEQ) || len == strlen(def->name)) { - ret = g_strdup_printf("%d-%.*s", def->id, VIR_DOMAIN_SHORT_NAME_MAX, def->name); - return ret; + return g_strdup_printf("%d-%.*s", def->id, VIR_DOMAIN_SHORT_NAME_MAX, + def->name); } if (len == (size_t) -1) { @@ -31362,8 +31361,7 @@ virDomainDefGetShortName(const virDomainDef *def) return NULL; } - ret = g_strdup_printf("%d-%s", def->id, shortname); - return ret; + return g_strdup_printf("%d-%s", def->id, shortname); } #undef VIR_DOMAIN_SHORT_NAME_MAX diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index a7c177f8db..dc64ce6959 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2892,10 +2892,7 @@ char * virNetworkConfigFile(const char *dir, const char *name) { - char *ret = NULL; - - ret = g_strdup_printf("%s/%s.xml", dir, name); - return ret; + return g_strdup_printf("%s/%s.xml", dir, name); } diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index a4cffea8b6..2013e11dff 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -432,10 +432,7 @@ static char * virNetworkPortDefConfigFile(const char *dir, const char *name) { - char *ret = NULL; - - ret = g_strdup_printf("%s/%s.xml", dir, name); - return ret; + return g_strdup_printf("%s/%s.xml", dir, name); } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 47f88481c8..c7e58f92ae 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4467,7 +4467,6 @@ char * virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) { virBuffer buf = VIR_BUFFER_INITIALIZER; - char *ret = NULL; size_t i; virBufferAddLit(&buf, "\n"); @@ -4537,9 +4536,7 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - ret = virBufferContentAndReset(&buf); - - return ret; + return virBufferContentAndReset(&buf); } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6acfc0b19d..269bdbaf56 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -251,7 +251,6 @@ qemuBuildMasterKeyCommandLine(virCommandPtr cmd, static char * qemuVirCommandGetFDSet(virCommandPtr cmd, int fd) { - char *result = NULL; int idx = virCommandPassFDGetFDIndex(cmd, fd); if (idx < 0) { @@ -260,8 +259,7 @@ qemuVirCommandGetFDSet(virCommandPtr cmd, int fd) return NULL; } - result = g_strdup_printf("set=%d,fd=%d", idx, fd); - return result; + return g_strdup_printf("set=%d,fd=%d", idx, fd); } @@ -278,7 +276,6 @@ qemuVirCommandGetFDSet(virCommandPtr cmd, int fd) static char * qemuVirCommandGetDevSet(virCommandPtr cmd, int fd) { - char *result = NULL; int idx = virCommandPassFDGetFDIndex(cmd, fd); if (idx < 0) { @@ -287,8 +284,7 @@ qemuVirCommandGetDevSet(virCommandPtr cmd, int fd) return NULL; } - result = g_strdup_printf("/dev/fdset/%d", idx); - return result; + return g_strdup_printf("/dev/fdset/%d", idx); } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index c59824006c..2d5e527b47 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1429,7 +1429,6 @@ char * qemuGetSharedDeviceKey(const char *device_path) { int maj, min; - char *key = NULL; int rc; if ((rc = virGetDeviceID(device_path, &maj, &min)) < 0) { @@ -1439,9 +1438,7 @@ qemuGetSharedDeviceKey(const char *device_path) return NULL; } - key = g_strdup_printf("%d:%d", maj, min); - - return key; + return g_strdup_printf("%d:%d", maj, min); } /* @@ -1706,7 +1703,6 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host; g_autofree char *dev_name = NULL; - char *dev_path = NULL; if (!(dev_name = virSCSIDeviceGetDevName(NULL, scsihostsrc->adapter, @@ -1715,8 +1711,7 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) scsihostsrc->unit))) return NULL; - dev_path = g_strdup_printf("/dev/%s", dev_name); - return dev_path; + return g_strdup_printf("/dev/%s", dev_name); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d63ec2313b..9c629c31a3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6837,15 +6837,12 @@ qemuDomainDefCopy(virQEMUDriverPtr driver, virDomainDefPtr src, unsigned int flags) { - virDomainDefPtr ret = NULL; g_autofree char *xml = NULL; if (!(xml = qemuDomainDefFormatXML(driver, qemuCaps, src, flags))) return NULL; - ret = qemuDomainDefFromXML(driver, qemuCaps, xml); - - return ret; + return qemuDomainDefFromXML(driver, qemuCaps, xml); } @@ -13364,11 +13361,8 @@ qemuProcessEventFree(struct qemuProcessEvent *event) char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv) { - char *ret = NULL; - - ret = g_strdup_printf("%s/%s.sock", priv->libDir, qemuDomainGetManagedPRAlias()); - - return ret; + return g_strdup_printf("%s/%s.sock", priv->libDir, + qemuDomainGetManagedPRAlias()); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d5aeeac66d..1c7c87128d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7439,31 +7439,25 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, static int qemuConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames) { virQEMUDriverPtr driver = conn->privateData; - int ret = -1; if (virConnectListDefinedDomainsEnsureACL(conn) < 0) return -1; - ret = virDomainObjListGetInactiveNames(driver->domains, names, nnames, - virConnectListDefinedDomainsCheckACL, - conn); - - return ret; + return virDomainObjListGetInactiveNames(driver->domains, names, nnames, + virConnectListDefinedDomainsCheckACL, + conn); } static int qemuConnectNumOfDefinedDomains(virConnectPtr conn) { virQEMUDriverPtr driver = conn->privateData; - int ret = -1; if (virConnectNumOfDefinedDomainsEnsureACL(conn) < 0) return -1; - ret = virDomainObjListNumOfDomains(driver->domains, false, - virConnectNumOfDefinedDomainsCheckACL, - conn); - - return ret; + return virDomainObjListNumOfDomains(driver->domains, false, + virConnectNumOfDefinedDomainsCheckACL, + conn); } diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 58dfdf689a..fe567f440c 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -171,11 +171,7 @@ static char * qemuTPMCreateEmulatorSocket(const char *swtpmStateDir, const char *shortName) { - char *path = NULL; - - path = g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName); - - return path; + return g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName); } @@ -213,14 +209,11 @@ static char * qemuTPMEmulatorCreatePidFilename(const char *swtpmStateDir, const char *shortName) { - char *pidfile = NULL; g_autofree char *devicename = NULL; devicename = g_strdup_printf("%s-swtpm", shortName); - pidfile = virPidFileBuildPath(swtpmStateDir, devicename); - - return pidfile; + return virPidFileBuildPath(swtpmStateDir, devicename); } diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 3bc200ffb3..7c8fd39584 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -213,12 +213,9 @@ static char * get_profile_name(virDomainDefPtr def) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *name = NULL; virUUIDFormat(def->uuid, uuidstr); - name = g_strdup_printf("%s%s", AA_PREFIX, uuidstr); - - return name; + return g_strdup_printf("%s%s", AA_PREFIX, uuidstr); } /* returns -1 on error or profile for libvirtd is unconfined, 0 if complain diff --git a/src/security/security_util.c b/src/security/security_util.c index 4f661fd75e..7fa5163fe4 100644 --- a/src/security/security_util.c +++ b/src/security/security_util.c @@ -92,9 +92,8 @@ virSecurityGetRefCountAttrName(const char *name G_GNUC_UNUSED) static char * virSecurityGetTimestampAttrName(const char *name) { - char *ret = NULL; - ret = g_strdup_printf(XATTR_NAMESPACE ".libvirt.security.timestamp_%s", name); - return ret; + return g_strdup_printf(XATTR_NAMESPACE ".libvirt.security.timestamp_%s", + name); } #else /* !XATTR_NAMESPACE */ static char * @@ -112,7 +111,6 @@ static char * virSecurityGetTimestamp(void) { unsigned long long boottime = 0; - char *ret = NULL; if (virHostGetBootTime(&boottime) < 0) { virReportSystemError(errno, "%s", @@ -120,8 +118,7 @@ virSecurityGetTimestamp(void) return NULL; } - ret = g_strdup_printf("%llu", boottime); - return ret; + return g_strdup_printf("%llu", boottime); } diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 2db763caa5..7e82c09be5 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2839,11 +2839,8 @@ virStoragePoolObjBuildTempFilePath(virStoragePoolObjPtr obj, { virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj); - char *tmp = NULL; - - tmp = g_strdup_printf("%s/%s.%s.secret.XXXXXX", - driver->stateDir, def->name, voldef->name); - return tmp; + return g_strdup_printf("%s/%s.%s.secret.XXXXXX", driver->stateDir, + def->name, voldef->name); } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 70d85200cb..bb535df4f2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -423,7 +423,6 @@ virCgroupDetect(virCgroupPtr group, char * virCgroupGetBlockDevString(const char *path) { - char *ret = NULL; struct stat sb; if (stat(path, &sb) < 0) { @@ -442,9 +441,7 @@ virCgroupGetBlockDevString(const char *path) /* Automatically append space after the string since all callers * use it anyway */ - ret = g_strdup_printf("%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)); - - return ret; + return g_strdup_printf("%d:%d ", major(sb.st_rdev), minor(sb.st_rdev)); } diff --git a/src/util/virmdev.c b/src/util/virmdev.c index c2499c0a20..51a88a91d7 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -209,7 +209,6 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) g_autofree char *result_file = NULL; g_autofree char *iommu_path = NULL; g_autofree char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr); - char *vfio_path = NULL; if (!dev_path) return NULL; @@ -228,9 +227,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) result_file = g_path_get_basename(result_path); - vfio_path = g_strdup_printf("/dev/vfio/%s", result_file); - - return vfio_path; + return g_strdup_printf("/dev/vfio/%s", result_file); } @@ -422,10 +419,7 @@ virMediatedDeviceIsUsed(virMediatedDevicePtr dev, char * virMediatedDeviceGetSysfsPath(const char *uuidstr) { - char *ret = NULL; - - ret = g_strdup_printf(MDEV_SYSFS_DEVICES "%s", uuidstr); - return ret; + return g_strdup_printf(MDEV_SYSFS_DEVICES "%s", uuidstr); } diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index c537d606cc..e17f6bd1bd 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2308,8 +2308,6 @@ virResctrlDeterminePath(const char *parentpath, const char *prefix, const char *id) { - char *path = NULL; - if (!id) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Resctrl ID must be set before determining resctrl " @@ -2317,9 +2315,7 @@ virResctrlDeterminePath(const char *parentpath, return NULL; } - path = g_strdup_printf("%s/%s-%s", parentpath, prefix, id); - - return path; + return g_strdup_printf("%s/%s-%s", parentpath, prefix, id); } diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 4c9f124e88..a858a69204 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -578,7 +578,6 @@ char * virSocketAddrGetPath(virSocketAddrPtr addr G_GNUC_UNUSED) { #ifndef WIN32 - char *path = NULL; if (addr == NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("No socket address provided")); @@ -591,9 +590,7 @@ virSocketAddrGetPath(virSocketAddrPtr addr G_GNUC_UNUSED) return NULL; } - path = g_strndup(addr->data.un.sun_path, sizeof(addr->data.un.sun_path)); - - return path; + return g_strndup(addr->data.un.sun_path, sizeof(addr->data.un.sun_path)); #else virReportError(VIR_ERR_NO_SUPPORT, "%s", _("UNIX sockets not supported on this platform")); diff --git a/src/util/virutil.c b/src/util/virutil.c index 5b52e4e6d4..fb46501142 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1420,7 +1420,6 @@ virGetUnprivSGIOSysfsPath(const char *path, const char *sysfs_dir) { int maj, min; - char *sysfs_path = NULL; int rc; if ((rc = virGetDeviceID(path, &maj, &min)) < 0) { @@ -1430,10 +1429,9 @@ virGetUnprivSGIOSysfsPath(const char *path, return NULL; } - sysfs_path = g_strdup_printf("%s/%d:%d/queue/unpriv_sgio", - sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, - maj, min); - return sysfs_path; + return g_strdup_printf("%s/%d:%d/queue/unpriv_sgio", + sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, maj, + min); } int diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4a303c0185..04febd1b0c 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -185,11 +185,7 @@ fakeStorageVolGetInfo(virStorageVolPtr vol, static char * fakeStorageVolGetPath(virStorageVolPtr vol) { - char *ret = NULL; - - ret = g_strdup_printf("/some/%s/device/%s", vol->key, vol->name); - - return ret; + return g_strdup_printf("/some/%s/device/%s", vol->key, vol->name); } -- GitLab