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 <axel.lin@ingics.com>
This commit is contained in:
Axel Lin 2015-12-06 00:09:33 +08:00 committed by Dirk Ziegelmeier
parent 8bb27ba8c4
commit a709041b8b
2 changed files with 4 additions and 20 deletions

View File

@ -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;
}

View File

@ -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;
}