wifi: ath9k: Clean up device initialisation guards
PATCH 1/1 wifi: ath9k: Clean up device initialisation guards
The ath9k driver has a couple of guards against the RX path running until device initialisation has completed. However, they are problematic for several reasons:
- They use smp_wmb() paired with a data_race() annotation, instead of the idiomatic smb_store_release()/smb_load_acquire() pair.
- The guard in ath9k_wmi_event_tasklet() is weirdly late in the function.
- There are two of them when there's really no reason the rx init gets to run before the whole initialisation is complete.
Consolidate the guards on the single ath9k_htc_priv->initialized variable and use smb_store_release()/smb_load_acquire() to access it. Move the store into ath9k_init_device() to make sure it's set in all paths in the driver.
--- drivers/net/wireless/ath/ath9k/htc.h | 1 - drivers/net/wireless/ath/ath9k/htc_drv_init.c | 7 +++---- drivers/net/wireless/ath/ath9k/htc_drv_txrx.c | 8 ++------ drivers/net/wireless/ath/ath9k/wmi.c | 12 ++++++------ 4 files changed, 11 insertions(+), 17 deletions(-)
drivers/net/wireless/ath/ath9k/htc.h +0 -1
@@ -281,7 +281,6 @@ struct ath9k_htc_rxbuf {struct ath9k_htc_rx {struct list_head rxbuf;spinlock_t rxbuflock; -bool initialized; };#define ATH9K_HTC_TX_CLEANUP_INTERVAL 50/* ms */
drivers/net/wireless/ath/ath9k/htc_drv_init.c +3 -4
@@ -910,6 +910,9 @@ static int ath9k_init_device(struct ath9k_htc_priv *priv,ath9k_init_leds (priv);ath9k_start_rfkill_poll (priv); +/* signal completion to ath9k_htc_rxep() and ath9k_wmi_event_tasklet() */ +smp_store_release (&priv->initialized, true); +return 0 ; err_world:
@@ -966,10 +969,6 @@ int ath9k_htc_probe_device(struct htc_target *htc_handle, struct device *dev, htc_handle->drv_priv = priv; -/* Allow ath9k_wmi_event_tasklet() to operate. */ -smp_wmb (); - priv->initialized = true; -return 0 ; err_init:
drivers/net/wireless/ath/ath9k/htc_drv_txrx.c +2 -6
@@ -1141,8 +1141,8 @@ void ath9k_htc_rxep(void *drv_priv, struct sk_buff *skb,struct ath9k_htc_rxbuf *rxbuf =NULL , *tmp_buf =NULL ;unsigned long flags; -/* Check if ath9k_rx_init() completed. */ -if (!data_race (priv->rx.initialized)) +/* Check if ath9k_init_device() completed. */ +if (!smp_load_acquire (&priv->initialized)) goto err;spin_lock_irqsave (&priv->rx.rxbuflock, flags);
@@ -1200,10 +1200,6 @@ int ath9k_rx_init(struct ath9k_htc_priv *priv)list_add_tail (&rxbuf->list, &priv->rx.rxbuf); } -/* Allow ath9k_htc_rxep() to operate. */ -smp_wmb (); - priv->rx.initialized = true; -return 0 ; err:
drivers/net/wireless/ath/ath9k/wmi.c +6 -6
@@ -146,6 +146,12 @@ void ath9k_wmi_event_tasklet(struct tasklet_struct *t)unsigned long flags;u16 cmd_id; +/* Check if ath9k_init_device() completed. */ +if (!smp_load_acquire (&priv->initialized)) { +tasklet_schedule (t); +return ; + } + do { spin_lock_irqsave(&wmi->wmi_lock, flags); skb = __skb_dequeue(&wmi->wmi_event_queue);
@@ -155,12 +161,6 @@ void ath9k_wmi_event_tasklet(struct tasklet_struct *t) }spin_unlock_irqrestore (&wmi->wmi_lock, flags); -/* Check if ath9k_htc_probe_device() completed. */ -if (!data_race (priv->initialized)) { -kfree_skb (skb); -continue ; - } - hdr = (struct wmi_cmd_hdr *) skb->data; cmd_id =be16_to_cpu (hdr->command_id); wmi_event =skb_pull (skb,sizeof (struct wmi_cmd_hdr ));
Signature · 1 line
2.55.0
Jeff Johnson
AppliedQuoted 8 lines · Toke Høiland-Jørgensen
The ath9k driver has a couple of guards against the RX path running until device initialisation has completed. However, they are problematic for several reasons:
- They use
smp_wmb()paired with adata_race()annotation, instead of the idiomatic smb_store_release()/smb_load_acquire() pair.[...]
Applied, thanks!
[1/1] wifi: ath9k: Clean up device initialisation guards
commit: 1af8dc9ca726cf53767f9c0661171396f95c146a
Best regards,
Signature · 1 line
Jeff Johnson <[email protected]>