[libvirt] [PATCH] util: netdevbridge: Refactor error handling in virNetDevBridgeCreate

Peter Krempa posted 1 patch 6 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/f6115a40d510c000ba5e0c8c1a01eeb388e5b0e5.1498652589.git.pkrempa@redhat.com
src/util/virnetdevbridge.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
[libvirt] [PATCH] util: netdevbridge: Refactor error handling in virNetDevBridgeCreate
Posted by Peter Krempa 6 years, 9 months ago
Replace the switch statement with a simpler if statement. This also
removes the fallthrough path that coverity was complaining about.
---
 src/util/virnetdevbridge.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
index 11b03b426..cfb7ebae9 100644
--- a/src/util/virnetdevbridge.c
+++ b/src/util/virnetdevbridge.c
@@ -468,22 +468,17 @@ virNetDevBridgeCreate(const char *brname)
         if (resp->nlmsg_len < NLMSG_LENGTH(sizeof(*err)))
             goto malformed_resp;

-        switch (err->error) {
-        case 0:
-            break;
-        case -EOPNOTSUPP:
+        if (err->error < 0) {
 # if defined(HAVE_STRUCT_IFREQ) && defined(SIOCBRADDBR)
-            /* fallback to ioctl if netlink doesn't support creating
-             * bridges
-             */
-            rc = virNetDevBridgeCreateWithIoctl(brname);
-            goto cleanup;
+            if (err->error == -EOPNOTSUPP) {
+                /* fallback to ioctl if netlink doesn't support creating
+                 * bridges
+                 */
+                rc = virNetDevBridgeCreateWithIoctl(brname);
+                goto cleanup;
+            }
 # endif
-            /* intentionally fall through if virNetDevBridgeCreateWithIoctl()
-             * isn't available.
-             */
-            ATTRIBUTE_FALLTHROUGH;
-        default:
+
             virReportSystemError(-err->error,
                                  _("error creating bridge interface %s"),
                                  brname);
-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: netdevbridge: Refactor error handling in virNetDevBridgeCreate
Posted by John Ferlan 6 years, 9 months ago

On 06/28/2017 08:23 AM, Peter Krempa wrote:
> Replace the switch statement with a simpler if statement. This also
> removes the fallthrough path that coverity was complaining about.
> ---
>  src/util/virnetdevbridge.c | 23 +++++++++--------------
>  1 file changed, 9 insertions(+), 14 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

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