From 60293a7a3656aab8c10f2d1827d1da88ad46d32c Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Fri, 29 Jun 2018 04:30:13 +0200 Subject: [PATCH] replace fall throughs in switch/cases where possible with simple code changes fall throughs are usually error-prone, especially when someone else extend it. Signed-off-by: Alexander Couzens Acked-by: Hans Dedecker --- alias.c | 11 ++++++----- interface.c | 18 ++++++++++-------- vlan.c | 6 +++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/alias.c b/alias.c index 649f2d1..3b14b87 100644 --- 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); diff --git a/interface.c b/interface.c index 400c605..e32f08a 100644 --- a/interface.c +++ b/interface.c @@ -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 067f624..84befc9 100644 --- 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); -- 2.25.1