Skip to content

Commit 1be9449

Browse files
TropicaoKalle Valo
authored and
Kalle Valo
committedJan 10, 2025
wifi: wilc1000: unregister wiphy only if it has been registered
There is a specific error path in probe functions in wilc drivers (both sdio and spi) which can lead to kernel panic, as this one for example when using SPI: Unable to handle kernel paging request at virtual address 9f000000 when read [9f000000] *pgd=00000000 Internal error: Oops: 5 [#1] ARM Modules linked in: wilc1000_spi(+) crc_itu_t crc7 wilc1000 cfg80211 bluetooth ecdh_generic ecc CPU: 0 UID: 0 PID: 106 Comm: modprobe Not tainted 6.13.0-rc3+ #22 Hardware name: Atmel SAMA5 PC is at wiphy_unregister+0x244/0xc40 [cfg80211] LR is at wiphy_unregister+0x1c0/0xc40 [cfg80211] [...] wiphy_unregister [cfg80211] from wilc_netdev_cleanup+0x380/0x494 [wilc1000] wilc_netdev_cleanup [wilc1000] from wilc_bus_probe+0x360/0x834 [wilc1000_spi] wilc_bus_probe [wilc1000_spi] from spi_probe+0x15c/0x1d4 spi_probe from really_probe+0x270/0xb2c really_probe from __driver_probe_device+0x1dc/0x4e8 __driver_probe_device from driver_probe_device+0x5c/0x140 driver_probe_device from __driver_attach+0x220/0x540 __driver_attach from bus_for_each_dev+0x13c/0x1a8 bus_for_each_dev from bus_add_driver+0x2a0/0x6a4 bus_add_driver from driver_register+0x27c/0x51c driver_register from do_one_initcall+0xf8/0x564 do_one_initcall from do_init_module+0x2e4/0x82c do_init_module from load_module+0x59a0/0x70c4 load_module from init_module_from_file+0x100/0x148 init_module_from_file from sys_finit_module+0x2fc/0x924 sys_finit_module from ret_fast_syscall+0x0/0x1c The issue can easily be reproduced, for example by not wiring correctly a wilc device through SPI (and so, make it unresponsive to early SPI commands). It is due to a recent change decoupling wiphy allocation from wiphy registration, however wilc_netdev_cleanup has not been updated accordingly, letting it possibly call wiphy unregister on a wiphy which has never been registered. Fix this crash by moving wiphy_unregister/wiphy_free out of wilc_netdev_cleanup, and by adjusting error paths in both drivers Fixes: fbdf0c5 ("wifi: wilc1000: Register wiphy after reading out chipid") Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com> Reviewed-by: Marek Vasut <marex@denx.de> Signed-off-by: Kalle Valo <kvalo@kernel.org> Link: https://patch.msgid.link/20241223-wilc_fix_probe_error_path-v1-1-91fa7bd8e5b6@bootlin.com
1 parent 89aca45 commit 1be9449

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed
 

‎drivers/net/wireless/microchip/wilc1000/netdev.c

-2
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,6 @@ void wilc_netdev_cleanup(struct wilc *wilc)
925925

926926
wilc_wlan_cfg_deinit(wilc);
927927
wlan_deinit_locks(wilc);
928-
wiphy_unregister(wilc->wiphy);
929-
wiphy_free(wilc->wiphy);
930928
}
931929
EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
932930

‎drivers/net/wireless/microchip/wilc1000/sdio.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int wilc_sdio_probe(struct sdio_func *func,
193193
ret = wilc_load_mac_from_nv(wilc);
194194
if (ret) {
195195
pr_err("Can not retrieve MAC address from chip\n");
196-
goto dispose_irq;
196+
goto unregister_wiphy;
197197
}
198198

199199
wilc_sdio_deinit(wilc);
@@ -202,15 +202,18 @@ static int wilc_sdio_probe(struct sdio_func *func,
202202
NL80211_IFTYPE_STATION, false);
203203
if (IS_ERR(vif)) {
204204
ret = PTR_ERR(vif);
205-
goto dispose_irq;
205+
goto unregister_wiphy;
206206
}
207207

208208
dev_info(&func->dev, "Driver Initializing success\n");
209209
return 0;
210210

211+
unregister_wiphy:
212+
wiphy_unregister(wilc->wiphy);
211213
dispose_irq:
212214
irq_dispose_mapping(wilc->dev_irq_num);
213215
wilc_netdev_cleanup(wilc);
216+
wiphy_free(wilc->wiphy);
214217
free:
215218
kfree(sdio_priv->cmd53_buf);
216219
kfree(sdio_priv);
@@ -222,7 +225,9 @@ static void wilc_sdio_remove(struct sdio_func *func)
222225
struct wilc *wilc = sdio_get_drvdata(func);
223226
struct wilc_sdio *sdio_priv = wilc->bus_data;
224227

228+
wiphy_unregister(wilc->wiphy);
225229
wilc_netdev_cleanup(wilc);
230+
wiphy_free(wilc->wiphy);
226231
kfree(sdio_priv->cmd53_buf);
227232
kfree(sdio_priv);
228233
}

‎drivers/net/wireless/microchip/wilc1000/spi.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,25 @@ static int wilc_bus_probe(struct spi_device *spi)
256256
ret = wilc_load_mac_from_nv(wilc);
257257
if (ret) {
258258
pr_err("Can not retrieve MAC address from chip\n");
259-
goto power_down;
259+
goto unregister_wiphy;
260260
}
261261

262262
wilc_wlan_power(wilc, false);
263263
vif = wilc_netdev_ifc_init(wilc, "wlan%d", WILC_STATION_MODE,
264264
NL80211_IFTYPE_STATION, false);
265265
if (IS_ERR(vif)) {
266266
ret = PTR_ERR(vif);
267-
goto power_down;
267+
goto unregister_wiphy;
268268
}
269269
return 0;
270270

271+
unregister_wiphy:
272+
wiphy_unregister(wilc->wiphy);
271273
power_down:
272274
wilc_wlan_power(wilc, false);
273275
netdev_cleanup:
274276
wilc_netdev_cleanup(wilc);
277+
wiphy_free(wilc->wiphy);
275278
free:
276279
kfree(spi_priv);
277280
return ret;
@@ -282,7 +285,9 @@ static void wilc_bus_remove(struct spi_device *spi)
282285
struct wilc *wilc = spi_get_drvdata(spi);
283286
struct wilc_spi *spi_priv = wilc->bus_data;
284287

288+
wiphy_unregister(wilc->wiphy);
285289
wilc_netdev_cleanup(wilc);
290+
wiphy_free(wilc->wiphy);
286291
kfree(spi_priv);
287292
}
288293

0 commit comments

Comments
 (0)
Please sign in to comment.