Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add init function for mbuf.
details: https://anonhg.NetBSD.org/src/rev/e684f39e6766
branches: trunk
changeset: 344785:e684f39e6766
user: knakahara <knakahara%NetBSD.org@localhost>
date: Wed Apr 20 08:50:43 2016 +0000
description:
Add init function for mbuf.
some functions use mbuf as stack variable instead of allocating by m_get().
They should use this function(s) to prevent access to uninitialized fields.
Currently, the mbuf stack allocating functions are the following.
+ sys/dev/ic/bwi.c
- bwi_rxeof()
- bwi_encap()
+ sys/dev/ic/dp8390.c
- dp8390_ipkdb_send()
+ sys/dev/pci/if_txp.c
- txp_download_fw_section()
+ sys/dev/ppbus/if_plip.c
- lptap()
+ sys/net/bpf.c
- _pf_mtap2()
- _pf_mtap_af()
- _pf_mtap_sl_out()
+ sys/netisdn/i4b_ipr.c
- ipr_rx_data_rdy()
- ipr_tx_queue_empty()
Reviewed by kre@n.o and christos@n.o, thanks.
diffstat:
sys/kern/uipc_mbuf.c | 22 +++++-----------------
sys/sys/mbuf.h | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 18 deletions(-)
diffs (98 lines):
diff -r c614421cefda -r e684f39e6766 sys/kern/uipc_mbuf.c
--- a/sys/kern/uipc_mbuf.c Wed Apr 20 06:51:03 2016 +0000
+++ b/sys/kern/uipc_mbuf.c Wed Apr 20 08:50:43 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_mbuf.c,v 1.163 2015/08/24 22:21:26 pooka Exp $ */
+/* $NetBSD: uipc_mbuf.c,v 1.164 2016/04/20 08:50:43 knakahara Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.163 2015/08/24 22:21:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.164 2016/04/20 08:50:43 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_mbuftrace.h"
@@ -583,14 +583,8 @@
return NULL;
mbstat_type_add(type, 1);
- mowner_init(m, type);
- m->m_ext_ref = m;
- m->m_type = type;
- m->m_len = 0;
- m->m_next = NULL;
- m->m_nextpkt = NULL;
- m->m_data = m->m_dat;
- m->m_flags = 0;
+
+ m_hdr_init(m, type, NULL, m->m_dat, 0);
return m;
}
@@ -604,13 +598,7 @@
if (m == NULL)
return NULL;
- m->m_data = m->m_pktdat;
- m->m_flags = M_PKTHDR;
- m->m_pkthdr.rcvif = NULL;
- m->m_pkthdr.len = 0;
- m->m_pkthdr.csum_flags = 0;
- m->m_pkthdr.csum_data = 0;
- SLIST_INIT(&m->m_pkthdr.tags);
+ m_pkthdr_init(m);
return m;
}
diff -r c614421cefda -r e684f39e6766 sys/sys/mbuf.h
--- a/sys/sys/mbuf.h Wed Apr 20 06:51:03 2016 +0000
+++ b/sys/sys/mbuf.h Wed Apr 20 08:50:43 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mbuf.h,v 1.159 2015/10/13 21:28:34 rjs Exp $ */
+/* $NetBSD: mbuf.h,v 1.160 2016/04/20 08:50:43 knakahara Exp $ */
/*-
* Copyright (c) 1996, 1997, 1999, 2001, 2007 The NetBSD Foundation, Inc.
@@ -934,6 +934,38 @@
return pktlen;
}
+static __inline void
+m_hdr_init(struct mbuf *m, short type, struct mbuf *next, char *data, int len)
+{
+
+ KASSERT(m != NULL);
+
+ mowner_init(m, type);
+ m->m_ext_ref = m; /* default */
+ m->m_type = type;
+ m->m_len = len;
+ m->m_next = next;
+ m->m_nextpkt = NULL; /* default */
+ m->m_data = data;
+ m->m_flags = 0; /* default */
+}
+
+static __inline void
+m_pkthdr_init(struct mbuf *m)
+{
+
+ KASSERT(m != NULL);
+
+ m->m_data = m->m_pktdat;
+ m->m_flags = M_PKTHDR;
+
+ m->m_pkthdr.rcvif = NULL;
+ m->m_pkthdr.len = 0;
+ m->m_pkthdr.csum_flags = 0;
+ m->m_pkthdr.csum_data = 0;
+ SLIST_INIT(&m->m_pkthdr.tags);
+}
+
void m_print(const struct mbuf *, const char *, void (*)(const char *, ...)
__printflike(1, 2));
Home |
Main Index |
Thread Index |
Old Index