Skip to content

Commit bb97bc2

Browse files
jerome-pouillergregkh
authored andcommitted
staging: wfx: standardize the error when vif does not exist
Smatch complains: drivers/staging/wfx/hif_rx.c:177 hif_scan_complete_indication() warn: potential NULL parameter dereference 'wvif' drivers/staging/wfx/data_tx.c:576 wfx_flush() warn: potential NULL parameter dereference 'wvif' Indeed, if the vif id returned by the device does not exist anymore, wdev_to_wvif() could return NULL. In add, the error is not handled uniformly in the code, sometime a WARN() is displayed but code continue, sometime a dev_warn() is displayed, sometime it is just not tested, ... This patch standardize that. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Jérôme Pouiller <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fd2575c commit bb97bc2

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

drivers/staging/wfx/data_tx.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ static void wfx_skb_dtor(struct wfx_vif *wvif, struct sk_buff *skb)
431431
sizeof(struct hif_req_tx) +
432432
req->fc_offset;
433433

434-
WARN_ON(!wvif);
434+
if (!wvif) {
435+
pr_warn("%s: vif associated with the skb does not exist anymore\n", __func__);
436+
return;
437+
}
435438
wfx_tx_policy_put(wvif, req->retry_policy_index);
436439
skb_pull(skb, offset);
437440
ieee80211_tx_status_irqsafe(wvif->wdev->hw, skb);

drivers/staging/wfx/hif_rx.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ static int hif_receive_indication(struct wfx_dev *wdev,
110110
const struct hif_ind_rx *body = buf;
111111

112112
if (!wvif) {
113-
dev_warn(wdev->dev, "ignore rx data for non-existent vif %d\n",
114-
hif->interface);
115-
return 0;
113+
dev_warn(wdev->dev, "%s: ignore rx data for non-existent vif %d\n",
114+
__func__, hif->interface);
115+
return -EIO;
116116
}
117117
skb_pull(skb, sizeof(struct hif_msg) + sizeof(struct hif_ind_rx));
118118
wfx_rx_cb(wvif, body, skb);
@@ -128,8 +128,8 @@ static int hif_event_indication(struct wfx_dev *wdev,
128128
int type = le32_to_cpu(body->event_id);
129129

130130
if (!wvif) {
131-
dev_warn(wdev->dev, "received event for non-existent vif\n");
132-
return 0;
131+
dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
132+
return -EIO;
133133
}
134134

135135
switch (type) {
@@ -161,7 +161,10 @@ static int hif_pm_mode_complete_indication(struct wfx_dev *wdev,
161161
{
162162
struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
163163

164-
WARN_ON(!wvif);
164+
if (!wvif) {
165+
dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
166+
return -EIO;
167+
}
165168
complete(&wvif->set_pm_mode_complete);
166169

167170
return 0;
@@ -173,7 +176,11 @@ static int hif_scan_complete_indication(struct wfx_dev *wdev,
173176
{
174177
struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
175178

176-
WARN_ON(!wvif);
179+
if (!wvif) {
180+
dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
181+
return -EIO;
182+
}
183+
177184
wfx_scan_complete(wvif);
178185

179186
return 0;
@@ -185,7 +192,10 @@ static int hif_join_complete_indication(struct wfx_dev *wdev,
185192
{
186193
struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
187194

188-
WARN_ON(!wvif);
195+
if (!wvif) {
196+
dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
197+
return -EIO;
198+
}
189199
dev_warn(wdev->dev, "unattended JoinCompleteInd\n");
190200

191201
return 0;
@@ -195,11 +205,15 @@ static int hif_suspend_resume_indication(struct wfx_dev *wdev,
195205
const struct hif_msg *hif,
196206
const void *buf)
197207
{
198-
struct wfx_vif *wvif = wdev_to_wvif(wdev, hif->interface);
199208
const struct hif_ind_suspend_resume_tx *body = buf;
209+
struct wfx_vif *wvif;
200210

201211
if (body->bc_mc_only) {
202-
WARN_ON(!wvif);
212+
wvif = wdev_to_wvif(wdev, hif->interface);
213+
if (!wvif) {
214+
dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
215+
return -EIO;
216+
}
203217
if (body->resume)
204218
wfx_suspend_resume_mc(wvif, STA_NOTIFY_AWAKE);
205219
else

drivers/staging/wfx/sta.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
619619
struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *)&sta->drv_priv;
620620
struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id);
621621

622+
if (!wvif) {
623+
dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
624+
return -EIO;
625+
}
622626
schedule_work(&wvif->update_tim_work);
623627
return 0;
624628
}

0 commit comments

Comments
 (0)