提交 86df5de5 编写于 作者: X Xiaomeng Tong 提交者: Kalle Valo

cw1200: fix incorrect check to determine if no element is found in list

The bug is here: "} else if (item) {".

The list iterator value will *always* be set and non-NULL by
list_for_each_entry(), so it is incorrect to assume that the iterator
value will be NULL if the list is empty or no element is found in list.

Use a new value 'iter' as the list iterator, while use the old value
'item' as a dedicated pointer to point to the found element, which
1. can fix this bug, due to now 'item' is NULL only if it's not found.
2. do not need to change all the uses of 'item' after the loop.
3. can also limit the scope of the list iterator 'iter' *only inside*
   the traversal loop by simply declaring 'iter' inside the loop in the
   future, as usage of the iterator outside of the list_for_each_entry
   is considered harmful. https://lkml.org/lkml/2022/2/17/1032

Fixes: a910e4a9 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
Signed-off-by: NXiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: NKalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220413091723.17596-1-xiam0nd.tong@gmail.com
上级 f3d82323
...@@ -91,23 +91,25 @@ static void __cw1200_queue_gc(struct cw1200_queue *queue, ...@@ -91,23 +91,25 @@ static void __cw1200_queue_gc(struct cw1200_queue *queue,
bool unlock) bool unlock)
{ {
struct cw1200_queue_stats *stats = queue->stats; struct cw1200_queue_stats *stats = queue->stats;
struct cw1200_queue_item *item = NULL, *tmp; struct cw1200_queue_item *item = NULL, *iter, *tmp;
bool wakeup_stats = false; bool wakeup_stats = false;
list_for_each_entry_safe(item, tmp, &queue->queue, head) { list_for_each_entry_safe(iter, tmp, &queue->queue, head) {
if (time_is_after_jiffies(item->queue_timestamp + queue->ttl)) if (time_is_after_jiffies(iter->queue_timestamp + queue->ttl)) {
item = iter;
break; break;
}
--queue->num_queued; --queue->num_queued;
--queue->link_map_cache[item->txpriv.link_id]; --queue->link_map_cache[iter->txpriv.link_id];
spin_lock_bh(&stats->lock); spin_lock_bh(&stats->lock);
--stats->num_queued; --stats->num_queued;
if (!--stats->link_map_cache[item->txpriv.link_id]) if (!--stats->link_map_cache[iter->txpriv.link_id])
wakeup_stats = true; wakeup_stats = true;
spin_unlock_bh(&stats->lock); spin_unlock_bh(&stats->lock);
cw1200_debug_tx_ttl(stats->priv); cw1200_debug_tx_ttl(stats->priv);
cw1200_queue_register_post_gc(head, item); cw1200_queue_register_post_gc(head, iter);
item->skb = NULL; iter->skb = NULL;
list_move_tail(&item->head, &queue->free_pool); list_move_tail(&iter->head, &queue->free_pool);
} }
if (wakeup_stats) if (wakeup_stats)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册