staging: rtl8712: fix wrong function output
authorSergei Krainov <sergei.krainov.lkd@gmail.com>
Fri, 9 Apr 2021 12:46:11 +0000 (14:46 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Apr 2021 14:16:10 +0000 (16:16 +0200)
Return NULL from r8712_find_network() if no matched wlan_network
was found. Code with a bug:

while (plist != phead) {
pnetwork = container_of(plist, struct wlan_network, list);
plist = plist->next;
if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
break;
}
spin_unlock_irqrestore(&scanned_queue->lock, irqL);
return pnetwork;

In this code last processed pnetwork returned if list end was reached
and no pnetwork matched test condition.

Signed-off-by: Sergei Krainov <sergei.krainov.lkd@gmail.com>
Link: https://lore.kernel.org/r/20210409124611.GA3981@test-VirtualBox
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8712/rtl871x_mlme.c

index 6328da8..ba4a71e 100644 (file)
@@ -146,6 +146,8 @@ static struct wlan_network *r8712_find_network(struct  __queue *scanned_queue,
                if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
                        break;
        }
+       if (plist == phead)
+               pnetwork = NULL;
        spin_unlock_irqrestore(&scanned_queue->lock, irqL);
        return pnetwork;
 }