replace fall throughs in switch/cases where possible with simple code changes
authorAlexander Couzens <lynxis@fe80.eu>
Fri, 29 Jun 2018 02:30:13 +0000 (04:30 +0200)
committerAlexander Couzens <lynxis@fe80.eu>
Wed, 11 Jul 2018 20:03:38 +0000 (22:03 +0200)
fall throughs are usually error-prone, especially when someone else extend
it.

Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Acked-by: Hans Dedecker <dedeckeh@gmail.com>
alias.c
interface.c
vlan.c

diff --git a/alias.c b/alias.c
index 649f2d1317deee9e08d89a0810fc832b8cccdf23..3b14b87b2154b0011fdc2410ee3e7a76947d27be 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -87,19 +87,20 @@ alias_device_set_state(struct device *dev, bool state)
 static void alias_device_cb(struct device_user *dep, enum device_event ev)
 {
        struct alias_device *alias;
-       bool new_state = false;
 
        alias = container_of(dep, struct alias_device, dep);
        switch (ev) {
        case DEV_EVENT_ADD:
-               new_state = true;
+               device_set_present(&alias->dev, true);
+               break;
        case DEV_EVENT_REMOVE:
-               device_set_present(&alias->dev, new_state);
+               device_set_present(&alias->dev, false);
                break;
        case DEV_EVENT_LINK_UP:
-               new_state = true;
+               device_set_link(&alias->dev, true);
+               break;
        case DEV_EVENT_LINK_DOWN:
-               device_set_link(&alias->dev, new_state);
+               device_set_link(&alias->dev, false);
                break;
        case DEV_EVENT_UPDATE_IFINDEX:
                device_set_ifindex(&alias->dev, dep->dev->ifindex);
index 400c605efc0c9887e4991f6dbf4775942138dc0c..e32f08a29050cc3e5eb138e32af62946d6b1c153 100644 (file)
@@ -387,26 +387,28 @@ static void
 interface_main_dev_cb(struct device_user *dep, enum device_event ev)
 {
        struct interface *iface;
-       bool new_state = false;
 
        iface = container_of(dep, struct interface, main_dev);
        switch (ev) {
        case DEV_EVENT_ADD:
-               new_state = true;
+               interface_set_available(iface, true);
+               break;
        case DEV_EVENT_REMOVE:
-               interface_set_available(iface, new_state);
-               if (!new_state && dep->dev && dep->dev->external)
+               interface_set_available(iface, false);
+               if (dep->dev && dep->dev->external)
                        interface_set_main_dev(iface, NULL);
                break;
        case DEV_EVENT_UP:
-               new_state = true;
+               interface_set_enabled(iface, true);
+               break;
        case DEV_EVENT_DOWN:
-               interface_set_enabled(iface, new_state);
+               interface_set_enabled(iface, false);
                break;
        case DEV_EVENT_LINK_UP:
-               new_state = true;
+               interface_set_link_state(iface, true);
+               break;
        case DEV_EVENT_LINK_DOWN:
-               interface_set_link_state(iface, new_state);
+               interface_set_link_state(iface, false);
                break;
        case DEV_EVENT_TOPO_CHANGE:
                interface_proto_event(iface->proto, PROTO_CMD_RENEW, false);
diff --git a/vlan.c b/vlan.c
index 067f6245bf487f3661d49cd787017edadccfedec..84befc95b5c17f0ae45aba03e2b63b28cae16f8a 100644 (file)
--- a/vlan.c
+++ b/vlan.c
@@ -73,14 +73,14 @@ static void vlan_dev_set_name(struct vlan_device *vldev, struct device *dev)
 static void vlan_dev_cb(struct device_user *dep, enum device_event ev)
 {
        struct vlan_device *vldev;
-       bool new_state = false;
 
        vldev = container_of(dep, struct vlan_device, dep);
        switch(ev) {
        case DEV_EVENT_ADD:
-               new_state = true;
+               device_set_present(&vldev->dev, true);
+               break;
        case DEV_EVENT_REMOVE:
-               device_set_present(&vldev->dev, new_state);
+               device_set_present(&vldev->dev, false);
                break;
        case DEV_EVENT_UPDATE_IFNAME:
                vlan_dev_set_name(vldev, dep->dev);