From a709041b8bf2f5f1d87632d24cd4a76218dcd1d3 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 6 Dec 2015 00:09:33 +0800 Subject: [PATCH] Remove unnecessary p->len checking for pbuf_alloc calls with PBUF_RAM type pbuf_alloc() for PBUF_RAM type always return big enough memory on success. So checking p->len is not necessary. Testing if p is NULL or not is enough. Signed-off-by: Axel Lin --- src/core/ipv6/mld6.c | 6 +----- src/core/ipv6/nd6.c | 18 +++--------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/core/ipv6/mld6.c b/src/core/ipv6/mld6.c index 49b18e9e..fb976ab5 100644 --- a/src/core/ipv6/mld6.c +++ b/src/core/ipv6/mld6.c @@ -536,11 +536,7 @@ mld6_send(struct mld_group *group, u8_t type) /* Allocate a packet. Size is MLD header + IPv6 Hop-by-hop options header. */ p = pbuf_alloc(PBUF_IP, sizeof(struct mld_header) + sizeof(struct ip6_hbh_hdr), PBUF_RAM); - if ((p == NULL) || (p->len < (sizeof(struct mld_header) + sizeof(struct ip6_hbh_hdr)))) { - /* We couldn't allocate a suitable pbuf. drop it. */ - if (p != NULL) { - pbuf_free(p); - } + if (p == NULL) { MLD6_STATS_INC(mld6.memerr); return; } diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index e3f458d9..12b21ff4 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -855,11 +855,7 @@ nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags) /* Allocate a packet. */ lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0); p = pbuf_alloc(PBUF_IP, sizeof(struct ns_header) + (lladdr_opt_len << 3), PBUF_RAM); - if ((p == NULL) || (p->len < (sizeof(struct ns_header) + (lladdr_opt_len << 3)))) { - /* We couldn't allocate a suitable pbuf for the ns. drop it. */ - if (p != NULL) { - pbuf_free(p); - } + if (p == NULL) { ND6_STATS_INC(nd6.memerr); return; } @@ -923,11 +919,7 @@ nd6_send_na(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags) /* Allocate a packet. */ lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0); p = pbuf_alloc(PBUF_IP, sizeof(struct na_header) + (lladdr_opt_len << 3), PBUF_RAM); - if ((p == NULL) || (p->len < (sizeof(struct na_header) + (lladdr_opt_len << 3)))) { - /* We couldn't allocate a suitable pbuf for the ns. drop it. */ - if (p != NULL) { - pbuf_free(p); - } + if (p == NULL) { ND6_STATS_INC(nd6.memerr); return; } @@ -1005,11 +997,7 @@ nd6_send_rs(struct netif * netif) lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0); } p = pbuf_alloc(PBUF_IP, sizeof(struct rs_header) + (lladdr_opt_len << 3), PBUF_RAM); - if ((p == NULL) || (p->len < (sizeof(struct rs_header) + (lladdr_opt_len << 3)))) { - /* We couldn't allocate a suitable pbuf for the ns. drop it. */ - if (p != NULL) { - pbuf_free(p); - } + if (p == NULL) { ND6_STATS_INC(nd6.memerr); return ERR_BUF; }