From fc31564185dbdb73d0852ed4545fa0831ecf09bc Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 12 Feb 2016 20:52:53 +0000 Subject: [PATCH] Fix style around allocations from M_IP6NDP. - Don't cast the return value of malloc(9). - Use M_ZERO instead of explicitly calling bzero(9). MFC after: 1 week --- sys/netinet6/nd6.c | 2 +- sys/netinet6/nd6_rtr.c | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index da48a87e489..3655b4576d8 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -243,7 +243,7 @@ nd6_ifattach(struct ifnet *ifp) { struct nd_ifinfo *nd; - nd = (struct nd_ifinfo *)malloc(sizeof(*nd), M_IP6NDP, M_WAITOK|M_ZERO); + nd = malloc(sizeof(*nd), M_IP6NDP, M_WAITOK | M_ZERO); nd->initialized = 1; nd->chlim = IPV6_DEFHLIM; diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index ca649081368..895a06d8951 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -779,11 +779,10 @@ defrtrlist_update(struct nd_defrouter *new) if (new->rtlifetime == 0) return (NULL); - n = (struct nd_defrouter *)malloc(sizeof(*n), M_IP6NDP, M_NOWAIT); + n = malloc(sizeof(*n), M_IP6NDP, M_NOWAIT | M_ZERO); if (n == NULL) return (NULL); - bzero(n, sizeof(*n)); - *n = *new; + memcpy(n, new, sizeof(*n)); insert: /* @@ -826,10 +825,9 @@ pfxrtr_add(struct nd_prefix *pr, struct nd_defrouter *dr) { struct nd_pfxrouter *new; - new = (struct nd_pfxrouter *)malloc(sizeof(*new), M_IP6NDP, M_NOWAIT); + new = malloc(sizeof(*new), M_IP6NDP, M_NOWAIT | M_ZERO); if (new == NULL) return; - bzero(new, sizeof(*new)); new->router = dr; LIST_INSERT_HEAD(&pr->ndpr_advrtrs, new, pfr_entry); @@ -869,10 +867,9 @@ nd6_prelist_add(struct nd_prefixctl *pr, struct nd_defrouter *dr, int error = 0; char ip6buf[INET6_ADDRSTRLEN]; - new = (struct nd_prefix *)malloc(sizeof(*new), M_IP6NDP, M_NOWAIT); + new = malloc(sizeof(*new), M_IP6NDP, M_NOWAIT | M_ZERO); if (new == NULL) - return(ENOMEM); - bzero(new, sizeof(*new)); + return (ENOMEM); new->ndpr_ifp = pr->ndpr_ifp; new->ndpr_prefix = pr->ndpr_prefix; new->ndpr_plen = pr->ndpr_plen;