wifi: wfx: fix two minor issues in error paths
Jérôme Pouiller
maintainercover wifi: wfx: fix two minor issues in error paths
Both patches of this series fix minor issues located in error paths of the wfx driver. Neither of them is likely to be hit in practice and both have been there for years (since 2020).
They were found during the review of the series "wifi: wfx: fix possible device hang during init" [1], which reworks the error path of wfx_probe(): the first one by the Sashiko review bot, the second one by Alexander Sverdlin.
The first patch cancels a delayed work that could fire after the device has been removed and dereference the freed struct wfx_dev. The second one makes wfx_probe() return a proper errno instead of a leftover positive value when the firmware enforces the 'secure link' feature.
Note that AI tools have been involved in both patches. See the individual changelogs for the details.
This series applies on top of [1].
[1]: https://lore.kernel.org/all/[email protected]/
Jérôme Pouiller (2):
wifi: wfx: fix use-after-free of the cooling work on device removal
wifi: wfx: fix error code on unsupported firmware
drivers/net/wireless/silabs/wfx/main.c | 3 +++ 1 file changed, 3 insertions(+)
Signature · 1 line
2.47.3
Jérôme Pouiller
maintainerPATCH 1/2 wifi: wfx: fix use-after-free of the cooling work on device removal
When the device reports that it is too hot, wfx_suspend_hot_dev() blocks the Tx queues and arms cooling_timeout_work with a 10s delay. If the device recovers a normal temperature before the delay expires, the work is canceled. Else, the work declares the chip frozen and unblocks the Tx queues.
However, this work is never canceled when the device is removed. cooling_timeout_work is queued on the system workqueue, while struct wfx_dev is released by wfx_free_common() (through ieee80211_free_hw()). So, if the device is unbound during this 10s window, the work fires after struct wfx_dev has been freed and dereferences it.
Cancel the work during the teardown. It has to be done after wfx_bh_unregister(): the "device too hot" indication is processed by the bh, so canceling the work earlier would allow the bh to rearm it. On the other hand, the work calls wfx_tx_unlock(), which may in turn call wfx_bh_request_tx(). So it has to be canceled before bh_wq is destroyed.
Note that the Tx queues are intentionally left blocked: the device is going away, so there is nothing to unblock.
The issue was reported by the Sashiko review bot and the fix has been written by Copilot (including the commit log). The use-case is difficult to reproduce, so this code has not been tested. However, I don't believe this patch could cause any regression.
--- drivers/net/wireless/silabs/wfx/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/wireless/silabs/wfx/main.c +2 -0
@@ -487,6 +487,7 @@ int wfx_probe(struct wfx_dev *wdev) wdev->hwbus_ops->irq_unsubscribe (wdev->hwbus_priv); bh_unregister:wfx_bh_unregister (wdev); +cancel_delayed_work_sync (&wdev->cooling_timeout_work);destroy_workqueue (wdev->bh_wq);return err; }
@@ -497,6 +498,7 @@ void wfx_release(struct wfx_dev *wdev)wfx_hif_shutdown (wdev); wdev->hwbus_ops->irq_unsubscribe (wdev->hwbus_priv);wfx_bh_unregister (wdev); +cancel_delayed_work_sync (&wdev->cooling_timeout_work);destroy_workqueue (wdev->bh_wq); }
Signature · 1 line
2.47.3
Re: [PATCH wireless-next 1/2] wifi: wfx: fix use-after-free of the cooling work on device removal
Hi Jérôme,
Quoted 26 lines · Jérôme Pouiller
When the device reports that it is too hot,
wfx_suspend_hot_dev()blocks the Tx queues and armscooling_timeout_workwith a 10s delay. If the device recovers a normal temperature before the delay expires, the work is canceled. Else, the work declares the chip frozen and unblocks the Tx queues.However, this work is never canceled when the device is removed.
cooling_timeout_workis queued on the system workqueue, while structwfx_devis released bywfx_free_common()(throughieee80211_free_hw()). So, if the device is unbound during this 10s window, the work fires after structwfx_devhas been freed and dereferences it.Cancel the work during the teardown. It has to be done after
wfx_bh_unregister(): the "device too hot" indication is processed by the bh, so canceling the work earlier would allow the bh to rearm it. On the other hand, the work callswfx_tx_unlock(), which may in turn callwfx_bh_request_tx(). So it has to be canceled beforebh_wqis destroyed.Note that the Tx queues are intentionally left blocked: the device is going away, so there is nothing to unblock.
The issue was reported by the Sashiko review bot and the fix has been written by Copilot (including the commit log). The use-case is difficult to reproduce, so this code has not been tested. However, I don't believe this patch could cause any regression.
Quoted 4 lines
Fixes 1d52d29983e5d ("staging: wfx: add support for 'device too hot' indication")Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by Copilot:claude-opus-5Signed-off-by Jérôme Pouiller <[email protected]>
thanks for the patch! Tested with rmmod, no regression visible,
Quoted 23 lines
---
drivers/net/wireless/silabs/wfx/main.c | 2 ++1 file changed, 2 insertions(+)drivers/net/wireless/silabs/wfx/main.c +0
-0@@ -487,6 +487,7 @@ int wfx_probe(struct wfx_dev *wdev) wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv);bh_unregister:
wfx_bh_unregister(wdev);drivers/net/wireless/silabs/wfx/main.c +1
-0+cancel_delayed_work_sync (&wdev->cooling_timeout_work);
destroy_workqueue(wdev->bh_wq);
return err;
}drivers/net/wireless/silabs/wfx/main.c +1
-0@@ -497,6 +498,7 @@ void wfx_release(struct wfx_dev *wdev) wfx_hif_shutdown(wdev); wdev->hwbus_ops->irq_unsubscribe(wdev->hwbus_priv); wfx_bh_unregister(wdev); +cancel_delayed_work_sync (&wdev->cooling_timeout_work); destroy_workqueue(wdev->bh_wq); }
Signature · 3 lines
Alexander Sverdlin Siemens AG www.siemens.com
Jérôme Pouiller
maintainerPATCH 2/2 wifi: wfx: fix error code on unsupported firmware
In reply to Jérôme PouillerThe 'secure link' feature is not supported by upstream (the reference code relies on mbedTLS to implement it, which is not an option for the Linux kernel).
If the firmware enforce the 'secure link' feature, wfx_probe() exits early. However, err still holds the value returned by the previous call to wait_for_completion_timeout(), which is the number of jiffies left before the timeout, hence strictly positive (the zero case is handled just above).
wfx_probe() therefore returns a positive value. The bus probe functions forward it as-is and the driver core negates it (see really_probe()). The device does not get bound, which is the expected outcome, but the reported error code is a meaningless negative jiffies count instead of an errno.
Return -EOPNOTSUPP, as already done a few lines above when the firmware API version is not supported.
Copilot reviewed the code and wrote some parts of the log.
--- drivers/net/wireless/silabs/wfx/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/silabs/wfx/main.c +1 -0
@@ -411,6 +411,7 @@ int wfx_probe(struct wfx_dev *wdev)if (wdev->hw_caps.link_mode ==SEC_LINK_ENFORCED ) {dev_err (wdev->dev,"chip require secure_link, but can't negotiate it\n" ); + err = -EOPNOTSUPP ; goto irq_unsubscribe; }
Signature · 1 line
2.47.3
Re: [PATCH wireless-next 2/2] wifi: wfx: fix error code on unsupported firmware
Hi Jérôme,
Quoted 10 lines · Jérôme Pouiller
The 'secure link' feature is not supported by upstream (the reference code relies on mbedTLS to implement it, which is not an option for the Linux kernel).
If the firmware enforce the 'secure link' feature,
wfx_probe()exits early. However, err still holds the value returned by the previous call towait_for_completion_timeout(), which is the number of jiffies left before the timeout, hence strictly positive (the zero case is handled just above).
Quoted 4 lines
wfx_probe()therefore returns a positive value. The bus probe functions forward it as-is and the driver core negates it (seereally_probe()). The device does not get bound, which is the expected outcome, but the reported error code is a meaningless negative jiffies count instead of
^^^^^^^^
minor: I suppose it should have read "positive"
Quoted 11 lines
an errno.
Return
-EOPNOTSUPP, as already done a few lines above when the firmware API version is not supported.Copilot reviewed the code and wrote some parts of the log.
Reported-by Alexander Sverdlin <[email protected]>Assisted-by Copilot:claude-opus-5Signed-off-by Jérôme Pouiller <[email protected]>
Quoted 15 lines
---
drivers/net/wireless/silabs/wfx/main.c | 1 +1 file changed, 1 insertion(+)drivers/net/wireless/silabs/wfx/main.c +0
-0@@ -411,6 +411,7 @@ int wfx_probe(struct wfx_dev *wdev)
if (wdev->hw_caps.link_mode==SEC_LINK_ENFORCED) {dev_err(wdev->dev, "chip require secure_link, but can't negotiate it\n");drivers/net/wireless/silabs/wfx/main.c +1
-0+ err = -EOPNOTSUPP ;goto
irq_unsubscribe;
}
Signature · 3 lines
Alexander Sverdlin Siemens AG www.siemens.com
Jérôme Pouiller
maintainerRe: [PATCH wireless-next 2/2] wifi: wfx: fix error code on unsupported firmware
Quoted 16 lines · Alexander
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
Hi Jérôme,
Quoted 10 lines · Jérôme Pouiller
The 'secure link' feature is not supported by upstream (the reference code relies on mbedTLS to implement it, which is not an option for the Linux kernel).
If the firmware enforce the 'secure link' feature,
wfx_probe()exits early. However, err still holds the value returned by the previous call towait_for_completion_timeout(), which is the number of jiffies left before the timeout, hence strictly positive (the zero case is handled just above).
Quoted 6 lines
Quoted 4 lines
wfx_probe()therefore returns a positive value. The bus probe functions forward it as-is and the driver core negates it (seereally_probe()). The device does not get bound, which is the expected outcome, but the reported error code is a meaningless negative jiffies count instead of^^^^^^^^minor: I suppose it should have read "positive"
I mean, really_probe() inverts the value:
/*
* Return probe errors as positive values so that the callers
* can distinguish them from other errors.
*/
ret = -ret;
goto probe_failed;So, the jiffies count become negative
Signature · 1 line
Jérôme Pouiller
Re: [PATCH wireless-next 2/2] wifi: wfx: fix error code on unsupported firmware
Hi Jérôme,
Quoted 19 lines · Jérôme Pouiller
Quoted 10 lines
Quoted 10 lines
The 'secure link' feature is not supported by upstream (the reference code relies on mbedTLS to implement it, which is not an option for the Linux kernel).
If the firmware enforce the 'secure link' feature,
wfx_probe()exits early. However, err still holds the value returned by the previous call towait_for_completion_timeout(), which is the number of jiffies left before the timeout, hence strictly positive (the zero case is handled just above).Quoted 6 lines
Quoted 4 lines
wfx_probe()therefore returns a positive value. The bus probe functions forward it as-is and the driver core negates it (seereally_probe()). The device does not get bound, which is the expected outcome, but the reported error code is a meaningless negative jiffies count instead of^^^^^^^^
minor: I suppose it should have read "positive"I mean,
really_probe()inverts the value:
Quoted 8 lines
/*
* Return probe errors as positive values so that the callers
* can distinguish them from other errors.
*/
ret = -ret;
gotoprobe_failed;So, the jiffies count become negative
you are right, I didn't realize the above explains the driver core ;-) Thanks for explanation and sorry for the noise!
Signature · 3 lines
Alexander Sverdlin Siemens AG www.siemens.com