summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuxianliang <[email protected]>2021-03-31 14:59:12 +0800
committerliuxianliang <[email protected]>2021-03-31 14:59:12 +0800
commit4431c4796fb3e26fb66c012feb8bf47f3292b473 (patch)
tree838335260b561becb9c8067706b8a7e0d59687f9
parent154d73a4e76f954ad67d94455e6000a3d168fbf6 (diff)
[fix] remove the possible critical zone risk
-rw-r--r--components/net/lwip-1.4.1/src/include/netif/ethernetif.h2
-rw-r--r--components/net/lwip-1.4.1/src/netif/ethernetif.c12
-rw-r--r--components/net/lwip-2.0.2/src/include/netif/ethernetif.h2
-rw-r--r--components/net/lwip-2.0.2/src/netif/ethernetif.c12
-rw-r--r--components/net/lwip-2.1.2/src/include/netif/ethernetif.h2
-rw-r--r--components/net/lwip-2.1.2/src/netif/ethernetif.c12
6 files changed, 33 insertions, 9 deletions
diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h
index b3ca8e2ffb..650ad32eff 100644
--- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h
+++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h
@@ -27,7 +27,7 @@ struct eth_device
rt_uint16_t flags;
rt_uint8_t link_changed;
rt_uint8_t link_status;
- rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */
+ rt_uint8_t rx_notice;
/* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev);
diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c
index 30e7ee5f6d..94d1f8d907 100644
--- a/components/net/lwip-1.4.1/src/netif/ethernetif.c
+++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c
@@ -469,6 +469,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
dev->flags = flags;
/* link changed status of device */
dev->link_changed = 0x00;
+ /* avoid send the same mail to mailbox */
+ dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
@@ -556,10 +558,12 @@ rt_err_t eth_device_ready(struct eth_device* dev)
dev->rx_notice = RT_TRUE;
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev);
}
+ else
+ return RT_EOK;
/* post message to Ethernet thread */
}
-
- return ERR_OK; /* netif is not initialized yet, just return. */
+ else
+ return -RT_ERROR; /* netif is not initialized yet, just return. */
}
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
@@ -652,7 +656,11 @@ static void eth_rx_thread_entry(void* parameter)
else
netifapi_netif_set_link_down(device->netif);
}
+
+ rt_enter_critical();
+ /* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
+ rt_exit_critical();
/* receive all of buffer */
while(1)
diff --git a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h
index d294c36813..1459e3241d 100644
--- a/components/net/lwip-2.0.2/src/include/netif/ethernetif.h
+++ b/components/net/lwip-2.0.2/src/include/netif/ethernetif.h
@@ -27,7 +27,7 @@ struct eth_device
rt_uint16_t flags;
rt_uint8_t link_changed;
rt_uint8_t link_status;
- rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */
+ rt_uint8_t rx_notice;
/* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev);
diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c
index 0146286b2a..28e3822cf7 100644
--- a/components/net/lwip-2.0.2/src/netif/ethernetif.c
+++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c
@@ -511,6 +511,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
dev->flags = flags;
/* link changed status of device */
dev->link_changed = 0x00;
+ /* avoid send the same mail to mailbox */
+ dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
@@ -605,10 +607,12 @@ rt_err_t eth_device_ready(struct eth_device* dev)
dev->rx_notice = RT_TRUE;
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev);
}
+ else
+ return RT_EOK;
/* post message to Ethernet thread */
}
-
- return ERR_OK; /* netif is not initialized yet, just return. */
+ else
+ return -RT_ERROR; /* netif is not initialized yet, just return. */
}
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
@@ -701,7 +705,11 @@ static void eth_rx_thread_entry(void* parameter)
else
netifapi_netif_set_link_down(device->netif);
}
+
+ rt_enter_critical();
+ /* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
+ rt_exit_critical();
/* receive all of buffer */
while(1)
diff --git a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h
index d294c36813..1459e3241d 100644
--- a/components/net/lwip-2.1.2/src/include/netif/ethernetif.h
+++ b/components/net/lwip-2.1.2/src/include/netif/ethernetif.h
@@ -27,7 +27,7 @@ struct eth_device
rt_uint16_t flags;
rt_uint8_t link_changed;
rt_uint8_t link_status;
- rt_uint8_t rx_notice; /* avoid send the same mail to mailbox */
+ rt_uint8_t rx_notice;
/* eth device interface */
struct pbuf* (*eth_rx)(rt_device_t dev);
diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c
index e2f8512d53..09a84f61e5 100644
--- a/components/net/lwip-2.1.2/src/netif/ethernetif.c
+++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c
@@ -514,6 +514,8 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, const char *name, rt_
dev->flags = flags;
/* link changed status of device */
dev->link_changed = 0x00;
+ /* avoid send the same mail to mailbox */
+ dev->rx_notice = 0x00;
dev->parent.type = RT_Device_Class_NetIf;
/* register to RT-Thread device manager */
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
@@ -607,10 +609,12 @@ rt_err_t eth_device_ready(struct eth_device* dev)
dev->rx_notice = RT_TRUE;
return rt_mb_send(&eth_rx_thread_mb, (rt_uint32_t)dev);
}
+ else
+ return RT_EOK;
/* post message to Ethernet thread */
}
-
- return ERR_OK; /* netif is not initialized yet, just return. */
+ else
+ return -RT_ERROR; /* netif is not initialized yet, just return. */
}
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
@@ -703,7 +707,11 @@ static void eth_rx_thread_entry(void* parameter)
else
netifapi_netif_set_link_down(device->netif);
}
+
+ rt_enter_critical();
+ /* 'rx_notice' will be modify in the interrupt or here */
device->rx_notice = RT_FALSE;
+ rt_exit_critical();
/* receive all of buffer */
while(1)