mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-16 03:40:09 +00:00
netif: Add proper lock protect for accessing netif->loop_first
All the reset part of the code accessing netif->loop_first has lock protection, the only missing part is "while (netif->loop_first != NULL)". Fix it by adding lock protect around the while loop. Also convert the code to use while{} loop instead of do .. while{} loop, then we can avoid NULL test for in pointer in each loop and reduce a level of indent. Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
parent
0e07ed4b13
commit
1d4cbe768d
@ -904,7 +904,6 @@ netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t* ad
|
|||||||
void
|
void
|
||||||
netif_poll(struct netif *netif)
|
netif_poll(struct netif *netif)
|
||||||
{
|
{
|
||||||
struct pbuf *in;
|
|
||||||
/* If we have a loopif, SNMP counters are adjusted for it,
|
/* If we have a loopif, SNMP counters are adjusted for it,
|
||||||
* if not they are adjusted for 'netif'. */
|
* if not they are adjusted for 'netif'. */
|
||||||
#if MIB2_STATS
|
#if MIB2_STATS
|
||||||
@ -916,15 +915,15 @@ netif_poll(struct netif *netif)
|
|||||||
#endif /* MIB2_STATS */
|
#endif /* MIB2_STATS */
|
||||||
SYS_ARCH_DECL_PROTECT(lev);
|
SYS_ARCH_DECL_PROTECT(lev);
|
||||||
|
|
||||||
do {
|
|
||||||
/* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
|
/* Get a packet from the list. With SYS_LIGHTWEIGHT_PROT=1, this is protected */
|
||||||
SYS_ARCH_PROTECT(lev);
|
SYS_ARCH_PROTECT(lev);
|
||||||
in = netif->loop_first;
|
while (netif->loop_first != NULL) {
|
||||||
if (in != NULL) {
|
struct pbuf *in, *in_end;
|
||||||
struct pbuf *in_end = in;
|
|
||||||
#if LWIP_LOOPBACK_MAX_PBUFS
|
#if LWIP_LOOPBACK_MAX_PBUFS
|
||||||
u8_t clen = 1;
|
u8_t clen = 1;
|
||||||
#endif /* LWIP_LOOPBACK_MAX_PBUFS */
|
#endif /* LWIP_LOOPBACK_MAX_PBUFS */
|
||||||
|
|
||||||
|
in = in_end = netif->loop_first;
|
||||||
while (in_end->len != in_end->tot_len) {
|
while (in_end->len != in_end->tot_len) {
|
||||||
LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
|
LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
|
||||||
in_end = in_end->next;
|
in_end = in_end->next;
|
||||||
@ -950,10 +949,8 @@ netif_poll(struct netif *netif)
|
|||||||
}
|
}
|
||||||
/* De-queue the pbuf from its successors on the 'loop_' list. */
|
/* De-queue the pbuf from its successors on the 'loop_' list. */
|
||||||
in_end->next = NULL;
|
in_end->next = NULL;
|
||||||
}
|
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
|
|
||||||
if (in != NULL) {
|
|
||||||
LINK_STATS_INC(link.recv);
|
LINK_STATS_INC(link.recv);
|
||||||
MIB2_STATS_NETIF_ADD(stats_if, ifinoctets, in->tot_len);
|
MIB2_STATS_NETIF_ADD(stats_if, ifinoctets, in->tot_len);
|
||||||
MIB2_STATS_NETIF_INC(stats_if, ifinucastpkts);
|
MIB2_STATS_NETIF_INC(stats_if, ifinucastpkts);
|
||||||
@ -961,11 +958,9 @@ netif_poll(struct netif *netif)
|
|||||||
if (ip_input(in, netif) != ERR_OK) {
|
if (ip_input(in, netif) != ERR_OK) {
|
||||||
pbuf_free(in);
|
pbuf_free(in);
|
||||||
}
|
}
|
||||||
/* Don't reference the packet any more! */
|
SYS_ARCH_PROTECT(lev);
|
||||||
in = NULL;
|
|
||||||
}
|
}
|
||||||
/* go on while there is a packet on the list */
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
} while (netif->loop_first != NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
|
#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
|
||||||
|
Loading…
x
Reference in New Issue
Block a user