Skip to contentSkip to conversation

wilc1000: Fix use of void pointer as a wrong struct type

PATCH Superseded Vsevolod Kozlov 2 participants 2 messages Feb 6, 2021 – Feb 9, 2021 Microchip WILC1000 wifi driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wilc1000: Fix use of void pointer as a wrong struct type

ac_classify() expects a struct sk_buff* as its second argument, which is a member of struct tx_complete_data. priv happens to be a pointer to struct tx_complete_data, so passing it directly to ac_classify() leads to wrong behaviour and occasional panics.

---
 drivers/net/wireless/microchip/wilc1000/wlan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/microchip/wilc1000/wlan.c +2 -1
index c12f27be9f79..04ed52c736ff 100644
@@ -415,6 +415,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
 	struct txq_entry_t *tqe;
 	struct wilc_vif *vif = netdev_priv(dev);
 	struct wilc *wilc;
+	struct tx_complete_data *tx_data = priv;
 	u8 q_num;
 
 	wilc = vif->wilc;
@@ -437,7 +438,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
 	tqe->priv = priv;
 	tqe->vif = vif;
 
-	q_num = ac_classify(wilc, priv);
+	q_num = ac_classify(wilc, tx_data->skb);
 	tqe->q_num = q_num;
 	if (ac_change(wilc, &q_num)) {
 		tx_complete_fn(priv, 0);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 lines · Vsevolod Kozlov

ac_classify() expects a struct sk_buff* as its second argument, which is a member of struct tx_complete_data. priv happens to be a pointer to struct tx_complete_data, so passing it directly to ac_classify() leads to wrong behaviour and occasional panics.

A perfect example why void pointers should be avoided.

Quoted 18 lines
---
 drivers/net/wireless/microchip/wilc1000/wlan.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/microchip/wilc1000/wlan.c +1 -0
index c12f27be9f79..04ed52c736ff 100644
@@ -415,6 +415,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
 	struct txq_entry_t *tqe;
 	struct wilc_vif *vif = netdev_priv(dev);
 	struct wilc *wilc;
+	struct tx_complete_data *tx_data = priv;
 	u8 q_num;
 
 	wilc = vif->wilc;

drivers/net/wireless/microchip/wilc1000/wlan.c int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer, · line 441

Quoted 5 lines
drivers/net/wireless/microchip/wilc1000/wlan.c +1 -1
@@ -437,7 +438,7 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
 	tqe->priv = priv;
 	tqe->vif = vif;
 
-	q_num = ac_classify(wilc, priv);
+	q_num = ac_classify(wilc, tx_data->skb);

I think a safer fix would be to change wilc_wlan_txq_add_net_pkt() to take that struct tx_complete_data *tx_data directly, and not use void pointer at all. At the same time you could remove the ugly cast from the caller:

netdev.c:740: queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches