device: move hotplug handling logic from system-linux.c to device.c
authorFelix Fietkau <nbd@nbd.name>
Sat, 19 Jun 2021 06:11:21 +0000 (08:11 +0200)
committerFelix Fietkau <nbd@nbd.name>
Sat, 19 Jun 2021 06:11:23 +0000 (08:11 +0200)
Preparation for dealing with wifi per-station devices

Signed-off-by: Felix Fietkau <nbd@nbd.name>
device.c
device.h
system-linux.c

index 9bad50734e74333cbe053c3d954b3b0d4164d82d..d8617fcab67e5451f1ed46247c83f0b70bb5bb12 100644 (file)
--- a/device.c
+++ b/device.c
@@ -1208,3 +1208,14 @@ static void __init simple_device_type_init(void)
 {
        device_type_add(&simple_device_type);
 }
+
+void device_hotplug_event(const char *name, bool add)
+{
+       struct device *dev;
+
+       dev = device_find(name);
+       if (!dev || dev->type != &simple_device_type)
+               return;
+
+       device_set_present(dev, add);
+}
index db6dc3359138633d594f5673ce8ea42c475f94b8..7d6c48ba9469e260f14f34b8db79f22e240f541d 100644 (file)
--- a/device.h
+++ b/device.h
@@ -356,5 +356,6 @@ device_link_active(struct device *dev)
 }
 
 bool device_check_ip6segmentrouting(void);
+void device_hotplug_event(const char *name, bool add);
 
 #endif
index b9e440e052d10080112561ea42365db835a1d0ac..d914a20da10a6fbb48a0459e1d8d619a6b668855 100644 (file)
@@ -678,18 +678,13 @@ handle_hotplug_msg(char *data, int size)
 {
        const char *subsystem = NULL, *interface = NULL, *interface_old = NULL;
        char *cur, *end, *sep;
-       struct device *dev;
        int skip;
-       bool add, move = false;
+       bool add;
 
-       if (!strncmp(data, "add@", 4))
+       if (!strncmp(data, "add@", 4) || !strncmp(data, "move@", 5))
                add = true;
        else if (!strncmp(data, "remove@", 7))
                add = false;
-       else if (!strncmp(data, "move@", 5)) {
-               add = true;
-               move = true;
-       }
        else
                return;
 
@@ -717,36 +712,13 @@ handle_hotplug_msg(char *data, int size)
                }
        }
 
-       if (subsystem && interface) {
-               if (move && interface_old)
-                       goto move;
-               else
-                       goto found;
-       }
-
-       return;
-
-move:
-       dev = device_find(interface_old);
-       if (!dev)
+       if (!subsystem || !interface)
                return;
 
-       if (dev->type != &simple_device_type)
-               goto found;
-
-       device_set_present(dev, false);
-
-       return;
-
-found:
-       dev = device_find(interface);
-       if (!dev)
-               return;
-
-       if (dev->type != &simple_device_type)
-               return;
+       if (interface_old)
+               device_hotplug_event(interface_old, false);
 
-       device_set_present(dev, add);
+       device_hotplug_event(interface, add);
 }
 
 static void