wireless: clean up prev_config handling
authorFelix Fietkau <nbd@nbd.name>
Fri, 15 Sep 2023 18:12:04 +0000 (20:12 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 15 Sep 2023 18:15:46 +0000 (20:15 +0200)
Always update prev_config directly after creating it

Signed-off-by: Felix Fietkau <nbd@nbd.name>
wireless.c

index 1e7d757e01d7b9de26b1e9cd5c99869a893a209f..958080eca2a56bbfe3dd765a30408f5caa57da8d 100644 (file)
@@ -438,6 +438,8 @@ wireless_device_run_handler(struct wireless_device *wdev, bool up)
                wdev->prev_config = NULL;
        } else {
                prepare_config(wdev, &b, up);
+               free(wdev->prev_config);
+               wdev->prev_config = up ? blob_memdup(b.head) : NULL;
                config = blobmsg_format_json(b.head, true);
        }
 
@@ -495,8 +497,6 @@ __wireless_device_set_up(struct wireless_device *wdev, int force)
        if ((!force && wdev->state != IFS_DOWN) || config_init)
                return;
 
-       free(wdev->prev_config);
-       wdev->prev_config = NULL;
        wdev->state = IFS_SETUP;
        wireless_device_run_handler(wdev, true);
 }
@@ -689,16 +689,6 @@ wdev_set_config_state(struct wireless_device *wdev, enum interface_config_state
                __wireless_device_set_down(wdev);
 }
 
-static void
-wdev_prepare_prev_config(struct wireless_device *wdev)
-{
-       if (wdev->prev_config)
-               return;
-
-       prepare_config(wdev, &b, false);
-       wdev->prev_config = blob_memdup(b.head);
-}
-
 static void
 wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new)
 {
@@ -709,7 +699,6 @@ wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new)
        wdev->serialize = wd_new->serialize;
        free(wd_new);
 
-       wdev_prepare_prev_config(wdev);
        if (blob_attr_equal(wdev->config, new_config) && wdev->disabled == disabled)
                return;