Re: [libvirt] [PATCH] Drop needless ret variable
On 10/23/19 6:47 PM, Daniel Henrique Barboza wrote: > > > On 10/23/19 10:39 AM, Michal Privoznik wrote: >> In few places we have the following code pattern: >> >> int ret; >> ... /* @ret is not accessed here */ >> ret = f(...); >> return ret; >> >> This pattern can be written less verbose: >> >> ... >> return f(...); >> >> This patch was generated with following coccinelle spatch: >> >> @@ >> type T; >> constant C; >> expression f; >> identifier ret; >> @@ >> -T ret = C; >> ... when != ret >> -ret = f; >> -return ret; >> +return f; >> >> Afterwards I needed to fix a few places, e.g. comment in >> virDomainNetIPParseXML() was removed too because coccinelle >> thinks it refers to @ret while in fact it doesn't. Also in few >> places it replaced @ret declaration with a few spaces instead of >> removing the line. But nothing terribly wrong. >> >> Signed-off-by: Michal Privoznik > > Good stuff. I wonder if this Coccinelle tool would make my life easier > in the 'cleanup: return' patch series I sent ... Probably, I don't know how easy it is to remove labels, but I've found this script which allows you to detect some: https://github.com/coccinelle/coccinellery/blob/master/CONTRIB/firehose/ret/ret.cocci > > Reviewed-by: Daniel Henrique Barboza > Pushed, thanks. Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Drop needless ret variable
On 10/23/19 10:39 AM, Michal Privoznik wrote: In few places we have the following code pattern: int ret; ... /* @ret is not accessed here */ ret = f(...); return ret; This pattern can be written less verbose: ... return f(...); This patch was generated with following coccinelle spatch: @@ type T; constant C; expression f; identifier ret; @@ -T ret = C; ... when != ret -ret = f; -return ret; +return f; Afterwards I needed to fix a few places, e.g. comment in virDomainNetIPParseXML() was removed too because coccinelle thinks it refers to @ret while in fact it doesn't. Also in few places it replaced @ret declaration with a few spaces instead of removing the line. But nothing terribly wrong. Signed-off-by: Michal Privoznik Good stuff. I wonder if this Coccinelle tool would make my life easier in the 'cleanup: return' patch series I sent ... Reviewed-by: Daniel Henrique Barboza -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Drop needless ret variable
In few places we have the following code pattern: int ret; ... /* @ret is not accessed here */ ret = f(...); return ret; This pattern can be written less verbose: ... return f(...); This patch was generated with following coccinelle spatch: @@ type T; constant C; expression f; identifier ret; @@ -T ret = C; ... when != ret -ret = f; -return ret; +return f; Afterwards I needed to fix a few places, e.g. comment in virDomainNetIPParseXML() was removed too because coccinelle thinks it refers to @ret while in fact it doesn't. Also in few places it replaced @ret declaration with a few spaces instead of removing the line. But nothing terribly wrong. Signed-off-by: Michal Privoznik --- src/bhyve/bhyve_driver.c| 38 +--- src/conf/checkpoint_conf.c | 5 +--- src/conf/domain_conf.c | 12 ++-- src/conf/snapshot_conf.c| 5 +--- src/conf/storage_conf.c | 17 --- src/conf/virnwfilterbindingobj.c| 5 +--- src/libvirt-stream.c| 7 ++--- src/libxl/libxl_driver.c| 36 --- src/lxc/lxc_driver.c| 36 --- src/lxc/lxc_native.c| 5 +--- src/network/bridge_driver.c | 38 +++- src/nwfilter/nwfilter_driver.c | 10 ++- src/phyp/phyp_driver.c | 5 +--- src/qemu/qemu_command.c | 19 src/qemu/qemu_driver.c | 19 src/qemu/qemu_firmware.c| 4 +-- src/qemu/qemu_monitor_json.c| 4 +-- src/qemu/qemu_process.c | 16 -- src/qemu/qemu_vhost_user.c | 4 +-- src/remote/remote_daemon_dispatch.c | 5 +--- src/storage/storage_backend_iscsi.c | 5 +--- src/test/test_driver.c | 34 ++ src/util/vircgroupv1.c | 6 +--- src/util/vircgroupv2.c | 6 +--- src/util/virdbus.c | 5 +--- src/util/virjson.c | 5 +--- src/util/virmdev.c | 5 +--- src/util/virscsi.c | 4 +-- src/util/virscsivhost.c | 5 +--- src/util/virstoragefile.c | 23 --- src/vbox/vbox_storage.c | 18 src/vz/vz_driver.c | 45 ++--- tests/qemuxml2argvmock.c| 5 +--- tests/virstoragetest.c | 4 +-- tools/virsh-completer-domain.c | 20 - tools/virsh-completer-host.c| 8 ++--- tools/virsh-completer-nodedev.c | 4 +-- tools/virsh-completer-pool.c| 4 +-- tools/virsh-completer-secret.c | 4 +-- tools/virsh-network.c | 5 +--- tools/vsh.c | 5 +--- 41 files changed, 143 insertions(+), 367 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index e3d984f69a..a2c8185c45 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -630,30 +630,24 @@ static int bhyveConnectListDomains(virConnectPtr conn, int *ids, int maxids) { bhyveConnPtr privconn = conn->privateData; -int n; if (virConnectListDomainsEnsureACL(conn) < 0) return -1; -n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, - virConnectListDomainsCheckACL, conn); - -return n; +return virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, +virConnectListDomainsCheckACL, conn); } static int bhyveConnectNumOfDomains(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; -int count; if (virConnectNumOfDomainsEnsureACL(conn) < 0) return -1; -count = virDomainObjListNumOfDomains(privconn->domains, true, - virConnectNumOfDomainsCheckACL, conn); - -return count; +return virDomainObjListNumOfDomains(privconn->domains, true, +virConnectNumOfDomainsCheckACL, conn); } static int @@ -661,31 +655,28 @@ bhyveConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) { bhyveConnPtr privconn = conn->privateData; -int n; if (virConnectListDefinedDomainsEnsureACL(conn) < 0) return -1; memset(names, 0, sizeof(*names) * maxnames); -n = virDomainObjListGetInactiveNames(privconn->domains, names, - maxnames, virConnectListDefinedDomainsCheckACL, conn); - -return n; +return virDomainObjListGetInactiveNames(privconn->domains, names, +maxnames, + virConnectListDefinedDomainsCheckACL, +conn); } static int bhyveConnectNumOfDefinedDomains(virConnectPtr conn) {
[libvirt] [PATCH] Drop needless @ret variable
In few places we have the following code pattern: int ret; ... /* @ret is not accessed here */ ret = f(...); return ret; This pattern can be written less verbose: ... return f(...); This patch was generated with following coccinelle spatch: @@ type T; constant C; expression f; identifier ret; @@ -T ret = C; ... when != ret -ret = f; -return ret; +return f; Afterwards I needed to fix a few places, e.g. comment in virDomainNetIPParseXML() was removed too because coccinelle thinks it refers to @ret while in fact it doesn't. Also in few places it replaced @ret declaration with a few spaces instead of removing the line. But nothing terribly wrong. Signed-off-by: Michal Privoznik --- src/bhyve/bhyve_driver.c| 38 +--- src/conf/checkpoint_conf.c | 5 +--- src/conf/domain_conf.c | 4 +-- src/conf/snapshot_conf.c| 5 +--- src/conf/storage_conf.c | 9 ++ src/conf/virnwfilterbindingobj.c| 5 +--- src/libvirt-stream.c| 7 ++--- src/libxl/libxl_driver.c| 36 --- src/lxc/lxc_driver.c| 36 --- src/lxc/lxc_native.c| 5 +--- src/network/bridge_driver.c | 38 +++- src/nwfilter/nwfilter_driver.c | 10 ++- src/phyp/phyp_driver.c | 5 +--- src/qemu/qemu_command.c | 14 - src/qemu/qemu_driver.c | 14 +++-- src/qemu/qemu_process.c | 16 -- src/remote/remote_daemon_dispatch.c | 5 +--- src/storage/storage_backend_iscsi.c | 5 +--- src/test/test_driver.c | 28 +- src/util/vircgroupv1.c | 6 +--- src/util/vircgroupv2.c | 6 +--- src/util/virdbus.c | 5 +--- src/vbox/vbox_storage.c | 18 src/vz/vz_driver.c | 45 ++--- tools/virsh-completer-domain.c | 4 +-- tools/virsh-completer-nodedev.c | 4 +-- tools/virsh-completer-pool.c| 4 +-- tools/virsh-completer-secret.c | 4 +-- tools/virsh-network.c | 5 +--- tools/vsh.c | 5 +--- 30 files changed, 115 insertions(+), 276 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 52e1895052..2e4f03d841 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -630,30 +630,24 @@ static int bhyveConnectListDomains(virConnectPtr conn, int *ids, int maxids) { bhyveConnPtr privconn = conn->privateData; -int n; if (virConnectListDomainsEnsureACL(conn) < 0) return -1; -n = virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, - virConnectListDomainsCheckACL, conn); - -return n; +return virDomainObjListGetActiveIDs(privconn->domains, ids, maxids, +virConnectListDomainsCheckACL, conn); } static int bhyveConnectNumOfDomains(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; -int count; if (virConnectNumOfDomainsEnsureACL(conn) < 0) return -1; -count = virDomainObjListNumOfDomains(privconn->domains, true, - virConnectNumOfDomainsCheckACL, conn); - -return count; +return virDomainObjListNumOfDomains(privconn->domains, true, +virConnectNumOfDomainsCheckACL, conn); } static int @@ -661,31 +655,28 @@ bhyveConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) { bhyveConnPtr privconn = conn->privateData; -int n; if (virConnectListDefinedDomainsEnsureACL(conn) < 0) return -1; memset(names, 0, sizeof(*names) * maxnames); -n = virDomainObjListGetInactiveNames(privconn->domains, names, - maxnames, virConnectListDefinedDomainsCheckACL, conn); - -return n; +return virDomainObjListGetInactiveNames(privconn->domains, names, +maxnames, + virConnectListDefinedDomainsCheckACL, +conn); } static int bhyveConnectNumOfDefinedDomains(virConnectPtr conn) { bhyveConnPtr privconn = conn->privateData; -int count; if (virConnectNumOfDefinedDomainsEnsureACL(conn) < 0) return -1; -count = virDomainObjListNumOfDomains(privconn->domains, false, - virConnectNumOfDefinedDomainsCheckACL, conn); - -return count; +return virDomainObjListNumOfDomains(privconn->domains, false, +virConnectNumOfDefinedDomainsCheckACL, +conn); } static char * @@ -771,17 +76