net: ipa: only set endpoint netdev pointer when in use
authorAlex Elder <elder@linaro.org>
Fri, 9 Apr 2021 18:07:18 +0000 (13:07 -0500)
committerJakub Kicinski <kuba@kernel.org>
Sat, 10 Apr 2021 03:57:25 +0000 (20:57 -0700)
In ipa_modem_start(), we set endpoint netdev pointers before the
network device is registered.  If registration fails, we don't undo
those assignments.  Instead, wait to assign the netdev pointer until
after registration succeeds.

Set these endpoint netdev pointers to NULL in ipa_modem_stop()
before unregistering the network device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ipa/ipa_modem.c

index 9b08eb8..8a6cceb 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 /* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
- * Copyright (C) 2018-2020 Linaro Ltd.
+ * Copyright (C) 2018-2021 Linaro Ltd.
  */
 
 #include <linux/errno.h>
@@ -213,18 +213,18 @@ int ipa_modem_start(struct ipa *ipa)
                goto out_set_state;
        }
 
-       ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = netdev;
-       ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = netdev;
-
        SET_NETDEV_DEV(netdev, &ipa->pdev->dev);
        priv = netdev_priv(netdev);
        priv->ipa = ipa;
 
        ret = register_netdev(netdev);
-       if (ret)
-               free_netdev(netdev);
-       else
+       if (!ret) {
                ipa->modem_netdev = netdev;
+               ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = netdev;
+               ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = netdev;
+       } else {
+               free_netdev(netdev);
+       }
 
 out_set_state:
        if (ret)
@@ -263,6 +263,8 @@ int ipa_modem_stop(struct ipa *ipa)
                if (ret)
                        goto out_set_state;
 
+               ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = NULL;
+               ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = NULL;
                ipa->modem_netdev = NULL;
                unregister_netdev(netdev);
                free_netdev(netdev);