Use pbuf_clone to replace pbuf_alloc+pbuf_copy

Use pbuf_clone() to simplify the code a bit.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
Axel Lin 2017-12-19 16:26:23 +08:00 committed by Dirk Ziegelmeier
parent 4cfef8acab
commit 61e90d9fc0
3 changed files with 4 additions and 23 deletions

View File

@ -154,14 +154,7 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
} }
#endif /* LWIP_SO_RCVBUF */ #endif /* LWIP_SO_RCVBUF */
/* copy the whole packet into new pbufs */ /* copy the whole packet into new pbufs */
q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); q = pbuf_clone(PBUF_RAW, PBUF_RAM, p);
if (q != NULL) {
if (pbuf_copy(q, p) != ERR_OK) {
pbuf_free(q);
q = NULL;
}
}
if (q != NULL) { if (q != NULL) {
u16_t len; u16_t len;
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF); buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);

View File

@ -1012,13 +1012,7 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
} }
if (copy_needed) { if (copy_needed) {
/* copy the whole packet into new pbufs */ /* copy the whole packet into new pbufs */
p = pbuf_alloc(PBUF_LINK, q->tot_len, PBUF_RAM); p = pbuf_clone(PBUF_LINK, PBUF_RAM, q);
if (p != NULL) {
if (pbuf_copy(p, q) != ERR_OK) {
pbuf_free(p);
p = NULL;
}
}
} else { } else {
/* referencing the old pbuf is enough */ /* referencing the old pbuf is enough */
p = q; p = q;

View File

@ -2046,7 +2046,7 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf *q)
} }
if (copy_needed) { if (copy_needed) {
/* copy the whole packet into new pbufs */ /* copy the whole packet into new pbufs */
p = pbuf_alloc(PBUF_LINK, q->tot_len, PBUF_RAM); p = pbuf_clone(PBUF_LINK, PBUF_RAM, q);
while ((p == NULL) && (neighbor_cache[neighbor_index].q != NULL)) { while ((p == NULL) && (neighbor_cache[neighbor_index].q != NULL)) {
/* Free oldest packet (as per RFC recommendation) */ /* Free oldest packet (as per RFC recommendation) */
#if LWIP_ND6_QUEUEING #if LWIP_ND6_QUEUEING
@ -2058,13 +2058,7 @@ nd6_queue_packet(s8_t neighbor_index, struct pbuf *q)
pbuf_free(neighbor_cache[neighbor_index].q); pbuf_free(neighbor_cache[neighbor_index].q);
neighbor_cache[neighbor_index].q = NULL; neighbor_cache[neighbor_index].q = NULL;
#endif /* LWIP_ND6_QUEUEING */ #endif /* LWIP_ND6_QUEUEING */
p = pbuf_alloc(PBUF_LINK, q->tot_len, PBUF_RAM); p = pbuf_clone(PBUF_LINK, PBUF_RAM, q);
}
if (p != NULL) {
if (pbuf_copy(p, q) != ERR_OK) {
pbuf_free(p);
p = NULL;
}
} }
} else { } else {
/* referencing the old pbuf is enough */ /* referencing the old pbuf is enough */