* [PATCH] staging: r8188eu: replace hand coded loop with list_for_each_entry
@ 2023-02-11 17:02 Martin Kaiser
2023-02-13 19:24 ` Philipp Hortmann
0 siblings, 1 reply; 2+ messages in thread
From: Martin Kaiser @ 2023-02-11 17:02 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
linux-staging, linux-kernel, Martin Kaiser
In function rtw_get_stainfo, we can use list_for_each_entry to iterate
over the list of stations and make the code a bit simpler.
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
drivers/staging/r8188eu/core/rtw_sta_mgt.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_sta_mgt.c b/drivers/staging/r8188eu/core/rtw_sta_mgt.c
index a9c29b2bf230..e1ae1859686e 100644
--- a/drivers/staging/r8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/r8188eu/core/rtw_sta_mgt.c
@@ -391,8 +391,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
/* any station allocated can be searched by hash list */
struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
{
- struct list_head *plist, *phead;
- struct sta_info *psta = NULL;
+ struct sta_info *ploop, *psta = NULL;
u32 index;
u8 *addr;
u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@ -409,18 +408,11 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
spin_lock_bh(&pstapriv->sta_hash_lock);
- phead = &pstapriv->sta_hash[index];
- plist = phead->next;
-
- while (phead != plist) {
- psta = container_of(plist, struct sta_info, hash_list);
-
- if ((!memcmp(psta->hwaddr, addr, ETH_ALEN))) {
- /* if found the matched address */
+ list_for_each_entry(ploop, &pstapriv->sta_hash[index], hash_list) {
+ if (!memcmp(ploop->hwaddr, addr, ETH_ALEN)) {
+ psta = ploop;
break;
}
- psta = NULL;
- plist = plist->next;
}
spin_unlock_bh(&pstapriv->sta_hash_lock);
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] staging: r8188eu: replace hand coded loop with list_for_each_entry
2023-02-11 17:02 [PATCH] staging: r8188eu: replace hand coded loop with list_for_each_entry Martin Kaiser
@ 2023-02-13 19:24 ` Philipp Hortmann
0 siblings, 0 replies; 2+ messages in thread
From: Philipp Hortmann @ 2023-02-13 19:24 UTC (permalink / raw)
To: Martin Kaiser, Greg Kroah-Hartman
Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
linux-staging, linux-kernel
On 2/11/23 18:02, Martin Kaiser wrote:
> In function rtw_get_stainfo, we can use list_for_each_entry to iterate
> over the list of stations and make the code a bit simpler.
>
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> ---
> drivers/staging/r8188eu/core/rtw_sta_mgt.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_sta_mgt.c b/drivers/staging/r8188eu/core/rtw_sta_mgt.c
> index a9c29b2bf230..e1ae1859686e 100644
> --- a/drivers/staging/r8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/r8188eu/core/rtw_sta_mgt.c
> @@ -391,8 +391,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
> /* any station allocated can be searched by hash list */
> struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
> {
> - struct list_head *plist, *phead;
> - struct sta_info *psta = NULL;
> + struct sta_info *ploop, *psta = NULL;
> u32 index;
> u8 *addr;
> u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
> @@ -409,18 +408,11 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
>
> spin_lock_bh(&pstapriv->sta_hash_lock);
>
> - phead = &pstapriv->sta_hash[index];
> - plist = phead->next;
> -
> - while (phead != plist) {
> - psta = container_of(plist, struct sta_info, hash_list);
> -
> - if ((!memcmp(psta->hwaddr, addr, ETH_ALEN))) {
> - /* if found the matched address */
> + list_for_each_entry(ploop, &pstapriv->sta_hash[index], hash_list) {
> + if (!memcmp(ploop->hwaddr, addr, ETH_ALEN)) {
> + psta = ploop;
> break;
> }
> - psta = NULL;
> - plist = plist->next;
> }
>
> spin_unlock_bh(&pstapriv->sta_hash_lock);
Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com> # Edimax N150
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-13 19:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-11 17:02 [PATCH] staging: r8188eu: replace hand coded loop with list_for_each_entry Martin Kaiser
2023-02-13 19:24 ` Philipp Hortmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox