[libvirt] [PATCH 1/2] nwfilter: Clean up virNWFilterDetermineMissingVarsRec returns

John Ferlan posted 2 patches 8 years, 4 months ago
[libvirt] [PATCH 1/2] nwfilter: Clean up virNWFilterDetermineMissingVarsRec returns
Posted by John Ferlan 8 years, 4 months ago
Rather than using loop break;'s in order to force a return
of rc = -1, let's just return -1 immediately on the various
error paths and then return 0 on the success path.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/nwfilter/nwfilter_gentech_driver.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
index 6758200b5..7a3d115ba 100644
--- a/src/nwfilter/nwfilter_gentech_driver.c
+++ b/src/nwfilter/nwfilter_gentech_driver.c
@@ -494,7 +494,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                                    virNWFilterDriverStatePtr driver)
 {
     virNWFilterObjPtr obj;
-    int rc = 0;
+    int rc;
     size_t i, j;
     virNWFilterDefPtr next_filter;
     virNWFilterDefPtr newNext_filter;
@@ -515,15 +515,13 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                     virNWFilterVarAccessPrint(rule->varAccess[j], &buf);
                     if (virBufferError(&buf)) {
                         virReportOOMError();
-                        rc = -1;
-                        break;
+                        return -1;
                     }
 
                     val = virNWFilterVarValueCreateSimpleCopyValue("1");
                     if (!val) {
                         virBufferFreeAndReset(&buf);
-                        rc = -1;
-                        break;
+                        return -1;
                     }
 
                     varAccess = virBufferContentAndReset(&buf);
@@ -532,21 +530,16 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
                     VIR_FREE(varAccess);
                 }
             }
-            if (rc)
-                break;
         } else if (inc) {
             VIR_DEBUG("Following filter %s", inc->filterref);
             if (!(obj = virNWFilterObjListFindInstantiateFilter(driver->nwfilters,
-                                                                inc->filterref))) {
-                rc = -1;
-                break;
-            }
+                                                                inc->filterref)))
+                return -1;
 
             /* create a temporary hashmap for depth-first tree traversal */
             if (!(tmpvars = virNWFilterCreateVarsFrom(inc->params, vars))) {
-                rc = -1;
                 virNWFilterObjUnlock(obj);
-                break;
+                return -1;
             }
 
             next_filter = virNWFilterObjGetDef(obj);
@@ -571,10 +564,10 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
 
             virNWFilterObjUnlock(obj);
             if (rc < 0)
-                break;
+                return -1;
         }
     }
-    return rc;
+    return 0;
 }
 
 
-- 
2.13.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] nwfilter: Clean up virNWFilterDetermineMissingVarsRec returns
Posted by Erik Skultety 8 years, 4 months ago
On Fri, Sep 29, 2017 at 09:31:08AM -0400, John Ferlan wrote:
> Rather than using loop break;'s in order to force a return
> of rc = -1, let's just return -1 immediately on the various
> error paths and then return 0 on the success path.
>
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/nwfilter/nwfilter_gentech_driver.c | 23 ++++++++---------------
>  1 file changed, 8 insertions(+), 15 deletions(-)
>
> diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c
> index 6758200b5..7a3d115ba 100644
> --- a/src/nwfilter/nwfilter_gentech_driver.c
> +++ b/src/nwfilter/nwfilter_gentech_driver.c
> @@ -494,7 +494,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
>                                     virNWFilterDriverStatePtr driver)
>  {
>      virNWFilterObjPtr obj;
> -    int rc = 0;
> +    int rc;

I prefer the variables to be initialized on the stack, it prevents the
unnecessary "may be uninitialized" warnings. It's a pity the other variables
are uninitialized, but that's for a patch for another time. With this hunk
dropped:

Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list