[PATCH] qemu: Decrease scope of variables in qemuConnectGetAllDomainStats()

Michal Privoznik posted 1 patch 2 years, 5 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/4d562ecb89f1c9b67c55abde1bc178e032af0c3f.1634547295.git.mprivozn@redhat.com
src/qemu/qemu_driver.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
[PATCH] qemu: Decrease scope of variables in qemuConnectGetAllDomainStats()
Posted by Michal Privoznik 2 years, 5 months ago
There are two variables (@vm and @domflags) in qemuConnectGetAllDomainStats()
that are used only within the for() loop but declared for entire function.
Bring them into the loop to make it obvious they are not used outside of it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_driver.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9bcba4b9a4..b9cc8f8379 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18811,14 +18811,12 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
     virQEMUDriver *driver = conn->privateData;
     virErrorPtr orig_err = NULL;
     virDomainObj **vms = NULL;
-    virDomainObj *vm;
     size_t nvms;
     virDomainStatsRecordPtr *tmpstats = NULL;
     bool enforce = !!(flags & VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS);
     int nstats = 0;
     size_t i;
     int ret = -1;
-    unsigned int domflags = 0;
     unsigned int lflags = flags & (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE |
                                    VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT |
                                    VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE);
@@ -18848,12 +18846,11 @@ qemuConnectGetAllDomainStats(virConnectPtr conn,
     tmpstats = g_new0(virDomainStatsRecordPtr, nvms + 1);
 
     for (i = 0; i < nvms; i++) {
+        virDomainObj *vm = vms[i];
         virDomainStatsRecordPtr tmp = NULL;
         unsigned int privflags = 0;
         unsigned int requestedStats = stats;
-
-        domflags = 0;
-        vm = vms[i];
+        unsigned int domflags = 0;
 
         virObjectLock(vm);
 
-- 
2.32.0

Re: [PATCH] qemu: Decrease scope of variables in qemuConnectGetAllDomainStats()
Posted by Erik Skultety 2 years, 5 months ago
On Mon, Oct 18, 2021 at 10:54:55AM +0200, Michal Privoznik wrote:
> There are two variables (@vm and @domflags) in qemuConnectGetAllDomainStats()
> that are used only within the for() loop but declared for entire function.
> Bring them into the loop to make it obvious they are not used outside of it.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
Reviewed-by: Erik Skultety <eskultet@redhat.com>