cw1200: fix incorrect check to determine if no element is found in list
authorXiaomeng Tong <xiam0nd.tong@gmail.com>
Wed, 13 Apr 2022 09:17:23 +0000 (17:17 +0800)
committerKalle Valo <kvalo@kernel.org>
Tue, 27 Sep 2022 06:08:31 +0000 (09:08 +0300)
commit86df5de5c632d3bd940f59bbb14ae912aa9cc363
tree68d45a20b9583b1c56227488e67471f07b60e00a
parentf3d8232331a3f4eaac1ab9a8679e5aedb2c33758
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: a910e4a94f692 ("cw1200: add driver for the ST-E CW1100 & CW1200 WLAN chipsets")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220413091723.17596-1-xiam0nd.tong@gmail.com
drivers/net/wireless/st/cw1200/queue.c