mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
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:
parent
945942ebba
commit
857df2fe50
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -117,10 +117,7 @@ virNWFilterObjListFree(virNWFilterObjList *nwfilters)
|
||||
virNWFilterObjList *
|
||||
virNWFilterObjListNew(void)
|
||||
{
|
||||
virNWFilterObjList *nwfilters;
|
||||
|
||||
nwfilters = g_new0(virNWFilterObjList, 1);
|
||||
return nwfilters;
|
||||
return g_new0(virNWFilterObjList, 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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? */
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 *
|
||||
|
@ -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 *
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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, ...)
|
||||
|
Loading…
Reference in New Issue
Block a user