]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: wilc1000: register net device only after bus being fully initialized
authorAlexis Lothoré <alexis.lothore@bootlin.com>
Tue, 14 May 2024 15:51:20 +0000 (17:51 +0200)
committerKalle Valo <kvalo@kernel.org>
Fri, 17 May 2024 08:01:51 +0000 (11:01 +0300)
SDIO/SPI probes functions automatically add a default wlan interface on top
of registered wiphy, through wilc_cfg80211_init which in turn calls
wilc_netdev_ifc_init. However, bus is still not fully initialized when we
register corresponding net device (for example we still miss some private
driver data pointers), which for example makes it impossible to
retrieve MAC address from chip (which is supposed to be set on net device
before its registration) before registering net device. More generally, net
device registration should not be done until driver has fully initialized
everything and is ready to handle any operation  on the net device.

Prevent net device from being registered so early by doing it at the end of
probe functions. Apply this logic to both sdio and spi buses.

Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240514-mac_addr_at_probe-v2-2-afef09f1cd10@bootlin.com
drivers/net/wireless/microchip/wilc1000/cfg80211.c
drivers/net/wireless/microchip/wilc1000/netdev.c
drivers/net/wireless/microchip/wilc1000/sdio.c
drivers/net/wireless/microchip/wilc1000/spi.c

index 7d9fb9f2d52799b1e1c92ae285943bdd921114a0..f716981f62ad4ea41f30212fafbd23f819b89f6e 100644 (file)
@@ -1773,7 +1773,6 @@ int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
                       const struct wilc_hif_func *ops)
 {
        struct wilc *wl;
-       struct wilc_vif *vif;
        int ret, i;
 
        wl = wilc_create_wiphy(dev);
@@ -1802,18 +1801,9 @@ int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
                ret = -ENOMEM;
                goto free_cfg;
        }
-       vif = wilc_netdev_ifc_init(wl, "wlan%d", WILC_STATION_MODE,
-                                  NL80211_IFTYPE_STATION, false);
-       if (IS_ERR(vif)) {
-               ret = PTR_ERR(vif);
-               goto free_hq;
-       }
 
        return 0;
 
-free_hq:
-       destroy_workqueue(wl->hif_workqueue);
-
 free_cfg:
        wilc_wlan_cfg_deinit(wl);
 
index acc9b9a6455241106635b1a1ed042cc6b8f73902..166165ee7712ec0816db21dc543266a6508c34f1 100644 (file)
@@ -996,6 +996,7 @@ error_remove_vif:
        free_netdev(ndev);
        return ERR_PTR(ret);
 }
+EXPORT_SYMBOL_GPL(wilc_netdev_ifc_init);
 
 MODULE_DESCRIPTION("Atmel WILC1000 core wireless driver");
 MODULE_LICENSE("GPL");
index 52a770c5e76f38cc553d448bd064eff3fa4f9797..a841dad084103c26132d08ceeceeb8a623fef93e 100644 (file)
@@ -136,9 +136,11 @@ out:
 static int wilc_sdio_probe(struct sdio_func *func,
                           const struct sdio_device_id *id)
 {
+       struct wilc_sdio *sdio_priv;
+       struct wilc_vif *vif;
        struct wilc *wilc;
        int ret;
-       struct wilc_sdio *sdio_priv;
+
 
        sdio_priv = kzalloc(sizeof(*sdio_priv), GFP_KERNEL);
        if (!sdio_priv)
@@ -176,9 +178,17 @@ static int wilc_sdio_probe(struct sdio_func *func,
        }
        clk_prepare_enable(wilc->rtc_clk);
 
+       vif = wilc_netdev_ifc_init(wilc, "wlan%d", WILC_STATION_MODE,
+                                  NL80211_IFTYPE_STATION, false);
+       if (IS_ERR(vif)) {
+               ret = PTR_ERR(vif);
+               goto clk_disable_unprepare;
+       }
+
        dev_info(&func->dev, "Driver Initializing success\n");
        return 0;
-
+clk_disable_unprepare:
+       clk_disable_unprepare(wilc->rtc_clk);
 dispose_irq:
        irq_dispose_mapping(wilc->dev_irq_num);
        wilc_netdev_cleanup(wilc);
index 61c3572ce32172b70e873a8c5b32c76924a222d8..add0e70a09eae1b0d6950a05bba288394b21109e 100644 (file)
@@ -206,9 +206,10 @@ static void wilc_wlan_power(struct wilc *wilc, bool on)
 
 static int wilc_bus_probe(struct spi_device *spi)
 {
-       int ret;
-       struct wilc *wilc;
        struct wilc_spi *spi_priv;
+       struct wilc_vif *vif;
+       struct wilc *wilc;
+       int ret;
 
        spi_priv = kzalloc(sizeof(*spi_priv), GFP_KERNEL);
        if (!spi_priv)
@@ -250,6 +251,12 @@ static int wilc_bus_probe(struct spi_device *spi)
                goto power_down;
 
        wilc_wlan_power(wilc, false);
+       vif = wilc_netdev_ifc_init(wilc, "wlan%d", WILC_STATION_MODE,
+                                  NL80211_IFTYPE_STATION, false);
+       if (IS_ERR(vif)) {
+               ret = PTR_ERR(vif);
+               goto power_down;
+       }
        return 0;
 
 power_down: