lib: Drop intermediary return variables

In a few places we declare a variable (which is optionally
followed by a code not touching it) then set the variable to a
value and return the variable immediately. It's obvious that the
variable is needless and the value can be returned directly
instead.

This patch was generated using this semantic patch:

  @@
  type T;
  identifier ret;
  expression E;
  @@
  - T ret;
  ... when != ret
      when strict
  - ret = E;
  - return ret;
  + return E;

After that I fixed couple of formatting issues because coccinelle
formatted some lines differently than our coding style.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2021-10-22 10:56:01 +02:00
parent 945942ebba
commit 857df2fe50
34 changed files with 54 additions and 190 deletions

View File

@ -36,11 +36,7 @@ VIR_LOG_INIT("bhyve.bhyve_domain");
static void *
bhyveDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED)
{
bhyveDomainObjPrivate *priv;
priv = g_new0(bhyveDomainObjPrivate, 1);
return priv;
return g_new0(bhyveDomainObjPrivate, 1);
}
static void

View File

@ -1862,11 +1862,7 @@ virDomainUSBAddressPortFormat(unsigned int *port)
virDomainUSBAddressSet *
virDomainUSBAddressSetCreate(void)
{
virDomainUSBAddressSet *addrs;
addrs = g_new0(virDomainUSBAddressSet, 1);
return addrs;
return g_new0(virDomainUSBAddressSet, 1);
}

View File

@ -28879,10 +28879,7 @@ char
*virDomainConfigFile(const char *dir,
const char *name)
{
char *ret;
ret = g_strdup_printf("%s/%s.xml", dir, name);
return ret;
return g_strdup_printf("%s/%s.xml", dir, name);
}
/* Translates a device name of the form (regex) "[fhv]d[a-z]+" into

View File

@ -1601,9 +1601,7 @@ char *
virNetworkObjGetPortStatusDir(virNetworkObj *net,
const char *stateDir)
{
char *ret;
ret = g_strdup_printf("%s/%s/ports", stateDir, net->def->name);
return ret;
return g_strdup_printf("%s/%s/ports", stateDir, net->def->name);
}
int

View File

@ -138,10 +138,7 @@ char *
virNWFilterBindingObjConfigFile(const char *dir,
const char *name)
{
char *ret;
ret = g_strdup_printf("%s/%s.xml", dir, name);
return ret;
return g_strdup_printf("%s/%s.xml", dir, name);
}

View File

@ -117,10 +117,7 @@ virNWFilterObjListFree(virNWFilterObjList *nwfilters)
virNWFilterObjList *
virNWFilterObjListNew(void)
{
virNWFilterObjList *nwfilters;
nwfilters = g_new0(virNWFilterObjList, 1);
return nwfilters;
return g_new0(virNWFilterObjList, 1);
}

View File

@ -1800,10 +1800,7 @@ esxDomainDestroy(virDomainPtr dom)
static char *
esxDomainGetOSType(virDomainPtr domain G_GNUC_UNUSED)
{
char *osType;
osType = g_strdup("hvm");
return osType;
return g_strdup("hvm");
}

View File

@ -766,10 +766,7 @@ esxStorageVolWipe(virStorageVolPtr volume G_GNUC_UNUSED,
static char *
esxStorageVolGetPath(virStorageVolPtr volume)
{
char *path;
path = g_strdup(volume->name);
return path;
return g_strdup(volume->name);
}

View File

@ -1392,10 +1392,7 @@ esxStorageVolGetXMLDesc(virStorageVolPtr volume,
static char *
esxStorageVolGetPath(virStorageVolPtr volume)
{
char *path;
path = g_strdup_printf("[%s] %s", volume->pool, volume->name);
return path;
return g_strdup_printf("[%s] %s", volume->pool, volume->name);
}

View File

@ -2234,10 +2234,7 @@ hypervDomainDestroy(virDomainPtr domain)
static char *
hypervDomainGetOSType(virDomainPtr domain G_GNUC_UNUSED)
{
char *osType;
osType = g_strdup("hvm");
return osType;
return g_strdup("hvm");
}

View File

@ -616,10 +616,7 @@ virLockDaemonExecRestartStatePath(bool privileged,
static char *
virLockDaemonGetExecRestartMagic(void)
{
char *ret;
ret = g_strdup_printf("%lld", (long long int)getpid());
return ret;
return g_strdup_printf("%lld", (long long int)getpid());
}

View File

@ -174,13 +174,11 @@ static int
virLockManagerSanlockInitLockspace(virLockManagerSanlockDriver *driver,
struct sanlk_lockspace *ls)
{
int ret;
const int max_hosts = 0; /* defaults used in sanlock_init() implementation */
const unsigned int lockspaceFlags = 0;
ret = sanlock_write_lockspace(ls, max_hosts, lockspaceFlags, driver->io_timeout);
return ret;
return sanlock_write_lockspace(ls, max_hosts, lockspaceFlags,
driver->io_timeout);
}
/* How many times try adding a lockspace? */

View File

@ -423,10 +423,7 @@ virLogDaemonExecRestartStatePath(bool privileged,
static char *
virLogDaemonGetExecRestartMagic(void)
{
char *ret;
ret = g_strdup_printf("%lld", (long long int)getpid());
return ret;
return g_strdup_printf("%lld", (long long int)getpid());
}

View File

@ -365,10 +365,7 @@ static char *
networkDnsmasqLeaseFileNameDefault(virNetworkDriverState *driver,
const char *netname)
{
char *leasefile;
leasefile = g_strdup_printf("%s/%s.leases", driver->dnsmasqStateDir, netname);
return leasefile;
return g_strdup_printf("%s/%s.leases", driver->dnsmasqStateDir, netname);
}
@ -376,10 +373,7 @@ static char *
networkDnsmasqLeaseFileNameCustom(virNetworkDriverState *driver,
const char *bridge)
{
char *leasefile;
leasefile = g_strdup_printf("%s/%s.status", driver->dnsmasqStateDir, bridge);
return leasefile;
return g_strdup_printf("%s/%s.status", driver->dnsmasqStateDir, bridge);
}
@ -387,21 +381,13 @@ static char *
networkDnsmasqConfigFileName(virNetworkDriverState *driver,
const char *netname)
{
char *conffile;
conffile = g_strdup_printf("%s/%s.conf", driver->dnsmasqStateDir, netname);
return conffile;
return g_strdup_printf("%s/%s.conf", driver->dnsmasqStateDir, netname);
}
static char *
networkRadvdPidfileBasename(const char *netname)
{
/* this is simple but we want to be sure it's consistently done */
char *pidfilebase;
pidfilebase = g_strdup_printf("%s-radvd", netname);
return pidfilebase;
{return g_strdup_printf("%s-radvd", netname);
}
@ -409,10 +395,7 @@ static char *
networkRadvdConfigFileName(virNetworkDriverState *driver,
const char *netname)
{
char *configfile;
configfile = g_strdup_printf("%s/%s-radvd.conf", driver->radvdStateDir, netname);
return configfile;
return g_strdup_printf("%s/%s-radvd.conf", driver->radvdStateDir, netname);
}

View File

@ -804,11 +804,7 @@ qemuAliasFromHostdev(const virDomainHostdevDef *hostdev)
char *
qemuDomainGetMasterKeyAlias(void)
{
char *alias;
alias = g_strdup("masterKey0");
return alias;
return g_strdup("masterKey0");
}
@ -837,11 +833,7 @@ qemuAliasForSecret(const char *parentalias,
char *
qemuAliasTLSObjFromSrcAlias(const char *srcAlias)
{
char *ret;
ret = g_strdup_printf("obj%s_tls0", srcAlias);
return ret;
return g_strdup_printf("obj%s_tls0", srcAlias);
}
@ -853,11 +845,7 @@ qemuAliasTLSObjFromSrcAlias(const char *srcAlias)
char *
qemuAliasChardevFromDevAlias(const char *devAlias)
{
char *ret;
ret = g_strdup_printf("char%s", devAlias);
return ret;
return g_strdup_printf("char%s", devAlias);
}
@ -871,11 +859,7 @@ qemuDomainGetManagedPRAlias(void)
char *
qemuDomainGetUnmanagedPRAlias(const char *parentalias)
{
char *ret;
ret = g_strdup_printf("pr-helper-%s", parentalias);
return ret;
return g_strdup_printf("pr-helper-%s", parentalias);
}

View File

@ -3811,18 +3811,15 @@ qemuBuildMemoryDeviceProps(const virDomainDef *def,
static char *
qemuBuildLegacyNicStr(virDomainNetDef *net)
{
char *str;
char macaddr[VIR_MAC_STRING_BUFLEN];
const char *netmodel = virDomainNetGetModelString(net);
str = g_strdup_printf("nic,macaddr=%s,netdev=host%s%s%s%s%s",
virMacAddrFormat(&net->mac, macaddr),
net->info.alias,
netmodel ? ",model=" : "",
NULLSTR_EMPTY(netmodel),
(net->info.alias ? ",id=" : ""),
NULLSTR_EMPTY(net->info.alias));
return str;
return g_strdup_printf("nic,macaddr=%s,netdev=host%s%s%s%s%s",
virMacAddrFormat(&net->mac, macaddr),
net->info.alias, netmodel ? ",model=" : "",
NULLSTR_EMPTY(netmodel),
(net->info.alias ? ",id=" : ""),
NULLSTR_EMPTY(net->info.alias));
}

View File

@ -5944,13 +5944,9 @@ qemuDomainDefFromXML(virQEMUDriver *driver,
virQEMUCaps *qemuCaps,
const char *xml)
{
virDomainDef *def;
def = virDomainDefParseString(xml, driver->xmlopt, qemuCaps,
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
return def;
return virDomainDefParseString(xml, driver->xmlopt, qemuCaps,
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
}

View File

@ -920,10 +920,7 @@ qemuMonitorClose(qemuMonitor *mon)
char *
qemuMonitorNextCommandID(qemuMonitor *mon)
{
char *id;
id = g_strdup_printf("libvirt-%d", ++mon->nextSerial);
return id;
return g_strdup_printf("libvirt-%d", ++mon->nextSerial);
}

View File

@ -1169,10 +1169,7 @@ static char *
AppArmorGetMountOptions(virSecurityManager *mgr G_GNUC_UNUSED,
virDomainDef *vm G_GNUC_UNUSED)
{
char *opts;
opts = g_strdup("");
return opts;
return g_strdup("");
}
static const char *

View File

@ -178,10 +178,7 @@ static char *
virSecurityDomainGetMountOptionsNop(virSecurityManager *mgr G_GNUC_UNUSED,
virDomainDef *vm G_GNUC_UNUSED)
{
char *opts;
opts = g_strdup("");
return opts;
return g_strdup("");
}
static const char *

View File

@ -1666,7 +1666,6 @@ static char *
testConnectGetSysinfo(virConnectPtr conn G_GNUC_UNUSED,
unsigned int flags)
{
char *ret;
const char *sysinfo = "<sysinfo type='smbios'>\n"
" <bios>\n"
" <entry name='vendor'>LENOVO</entry>\n"
@ -1678,8 +1677,7 @@ testConnectGetSysinfo(virConnectPtr conn G_GNUC_UNUSED,
virCheckFlags(0, NULL);
ret = g_strdup(sysinfo);
return ret;
return g_strdup(sysinfo);
}
static const char *
@ -2706,10 +2704,7 @@ testDomainCoreDump(virDomainPtr domain,
static char *
testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED)
{
char *ret;
ret = g_strdup("linux");
return ret;
return g_strdup("linux");
}

View File

@ -140,8 +140,6 @@ char *virAuditEncode(const char *key, const char *value)
#if WITH_AUDIT
return audit_encode_nv_string(key, value, 0);
#else
char *str;
str = g_strdup_printf("%s=%s", key, value);
return str;
return g_strdup_printf("%s=%s", key, value);
#endif
}

View File

@ -157,11 +157,7 @@ virFirewallSetBackend(virFirewallBackend backend)
static virFirewallGroup *
virFirewallGroupNew(void)
{
virFirewallGroup *group;
group = g_new0(virFirewallGroup, 1);
return group;
return g_new0(virFirewallGroup, 1);
}

View File

@ -267,11 +267,7 @@ char *
virMacMapFileName(const char *dnsmasqStateDir,
const char *bridge)
{
char *filename;
filename = g_strdup_printf("%s/%s.macs", dnsmasqStateDir, bridge);
return filename;
return g_strdup_printf("%s/%s.macs", dnsmasqStateDir, bridge);
}

View File

@ -2803,10 +2803,7 @@ static int virNetDevGetMulticastTable(const char *ifname,
virNetDevRxFilter *
virNetDevRxFilterNew(void)
{
virNetDevRxFilter *filter;
filter = g_new0(virNetDevRxFilter, 1);
return filter;
return g_new0(virNetDevRxFilter, 1);
}

View File

@ -1438,14 +1438,8 @@ void virPCIDeviceAddressCopy(virPCIDeviceAddress *dst,
char *
virPCIDeviceAddressAsString(const virPCIDeviceAddress *addr)
{
char *str;
str = g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT,
addr->domain,
addr->bus,
addr->slot,
addr->function);
return str;
return g_strdup_printf(VIR_PCI_DEVICE_ADDRESS_FMT, addr->domain,
addr->bus, addr->slot, addr->function);
}
bool

View File

@ -2699,16 +2699,15 @@ static int vboxDomainDestroy(virDomainPtr dom)
return vboxDomainDestroyFlags(dom, 0);
}
static char *vboxDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) {
static char *vboxDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED)
{
/* Returning "hvm" always as suggested on list, cause
* this functions seems to be badly named and it
* is supposed to pass the ABI name and not the domain
* operating system driver as I had imagined ;)
*/
char *osType;
osType = g_strdup("hvm");
return osType;
return g_strdup("hvm");
}
static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)

View File

@ -74,10 +74,7 @@ int virNetDevTapCreateInBridgePort(const char *brname G_GNUC_UNUSED,
char *virNetDevTapGetRealDeviceName(char *name G_GNUC_UNUSED)
{
char *fakename;
fakename = g_strdup("faketapdev");
return fakename;
return g_strdup("faketapdev");
}
int virNetDevSetOnline(const char *ifname G_GNUC_UNUSED,

View File

@ -1282,13 +1282,10 @@ qemuMonitorTestFullAddItem(qemuMonitorTest *test,
size_t line)
{
g_autofree char *cmderr = NULL;
int ret;
cmderr = g_strdup_printf("wrong expected command in %s:%zu: ", filename, line);
ret = qemuMonitorTestAddItemVerbatim(test, command, cmderr, response);
return ret;
return qemuMonitorTestAddItemVerbatim(test, command, cmderr, response);
}

View File

@ -128,11 +128,7 @@ static char *
get_key(const char *path,
const char *name)
{
char *ret;
ret = g_strdup_printf("%s:%s", path, name);
return ret;
return g_strdup_printf("%s:%s", path, name);
}

View File

@ -107,12 +107,9 @@ virNumaNodesetIsAvailable(virBitmap *nodeset)
char *
virTPMCreateCancelPath(const char *devpath)
{
char *path;
(void)devpath;
path = g_strdup("/sys/class/misc/tpm0/device/cancel");
return path;
return g_strdup("/sys/class/misc/tpm0/device/cancel");
}
/**

View File

@ -30,11 +30,7 @@ static void *
testClientNew(virNetServerClient *client G_GNUC_UNUSED,
void *opaque G_GNUC_UNUSED)
{
char *dummy;
dummy = g_new0(char, 1);
return dummy;
return g_new0(char, 1);
}

View File

@ -351,12 +351,8 @@ remove_fd(int fd)
static char *
pci_address_format(struct pciDeviceAddress const *addr)
{
char *ret;
ret = g_strdup_printf(ADDR_STR_FMT,
addr->domain, addr->bus,
addr->device, addr->function);
return ret;
return g_strdup_printf(ADDR_STR_FMT, addr->domain, addr->bus,
addr->device, addr->function);
}
static int

View File

@ -64,14 +64,12 @@ static char *get_fake_path(const char *real_path)
DIR *opendir(const char *name)
{
g_autofree char *path = NULL;
DIR* ret;
init_syms();
path = get_fake_path(name);
ret = realopendir(path);
return ret;
return realopendir(path);
}
int open(const char *pathname, int flags, ...)