wil6210: prevent usage of incorrect TX hwtail
authorMaya Erez <qca_merez@qca.qualcomm.com>
Thu, 18 Aug 2016 13:52:15 +0000 (16:52 +0300)
committerKalle Valo <kvalo@qca.qualcomm.com>
Fri, 19 Aug 2016 10:11:23 +0000 (13:11 +0300)
txdata->enabled is used in order to determine if the TX vring
is valid. As the data transmit is handled in a different context,
in case txdata->enabled is set before vring->hwtail is updated,
an old or corrupted vring->hwtail can be used.
Protect setting of txdata->enabled and vring->hwtail to prevent a
case where TX vring start handling TX packets before setting
vring->hwtail.

Signed-off-by: Maya Erez <qca_merez@qca.qualcomm.com>
Signed-off-by: Kalle Valo <kvalo@qca.qualcomm.com>
drivers/net/wireless/ath/wil6210/txrx.c

index f2f6a404d3d1c3480599e13e7b54addc1858adf1..4c38520d4dd2df523cdc05d3a74cf8425c2be371 100644 (file)
@@ -873,9 +873,12 @@ int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
                rc = -EINVAL;
                goto out_free;
        }
-       vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
 
+       spin_lock_bh(&txdata->lock);
+       vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
        txdata->enabled = 1;
+       spin_unlock_bh(&txdata->lock);
+
        if (txdata->dot1x_open && (agg_wsize >= 0))
                wil_addba_tx_request(wil, id, agg_wsize);
 
@@ -950,9 +953,11 @@ int wil_vring_init_bcast(struct wil6210_priv *wil, int id, int size)
                rc = -EINVAL;
                goto out_free;
        }
-       vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
 
+       spin_lock_bh(&txdata->lock);
+       vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
        txdata->enabled = 1;
+       spin_unlock_bh(&txdata->lock);
 
        return 0;
  out_free: