Fri Aug 18 15:08:02 2017 UTC ()
Pull up following revision(s) (requested by mrg in ticket #1477):
	sys/dev/ic/dm9000.c: revision 1.12
Check for MCLGET failure in dme_alloc_receive_buffer.
From Ilja Van Sprundel.


(snj)
diff -r1.4 -r1.4.16.1 src/sys/dev/ic/dm9000.c

cvs diff -r1.4 -r1.4.16.1 src/sys/dev/ic/dm9000.c (expand / switch to unified diff)

--- src/sys/dev/ic/dm9000.c 2012/01/28 08:29:55 1.4
+++ src/sys/dev/ic/dm9000.c 2017/08/18 15:08:02 1.4.16.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm9000.c,v 1.4 2012/01/28 08:29:55 nisimura Exp $ */ 1/* $NetBSD: dm9000.c,v 1.4.16.1 2017/08/18 15:08:02 snj Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009 Paul Fleischer 4 * Copyright (c) 2009 Paul Fleischer
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the company nor the name of the author may be used to 12 * 3. The name of the company nor the name of the author may be used to
13 * endorse or promote products derived from this software without specific 13 * endorse or promote products derived from this software without specific
14 * prior written permission. 14 * prior written permission.
@@ -1113,21 +1113,26 @@ dme_alloc_receive_buffer(struct ifnet *i @@ -1113,21 +1113,26 @@ dme_alloc_receive_buffer(struct ifnet *i
1113 struct mbuf *m; 1113 struct mbuf *m;
1114 int pad; 1114 int pad;
1115 1115
1116 MGETHDR(m, M_DONTWAIT, MT_DATA); 1116 MGETHDR(m, M_DONTWAIT, MT_DATA);
1117 m->m_pkthdr.rcvif = ifp; 1117 m->m_pkthdr.rcvif = ifp;
1118 /* Ensure that we always allocate an even number of 1118 /* Ensure that we always allocate an even number of
1119 * bytes in order to avoid writing beyond the buffer 1119 * bytes in order to avoid writing beyond the buffer
1120 */ 1120 */
1121 m->m_pkthdr.len = frame_length + (frame_length % sc->sc_data_width); 1121 m->m_pkthdr.len = frame_length + (frame_length % sc->sc_data_width);
1122 pad = ALIGN(sizeof(struct ether_header)) - 1122 pad = ALIGN(sizeof(struct ether_header)) -
1123 sizeof(struct ether_header); 1123 sizeof(struct ether_header);
1124 /* All our frames have the CRC attached */ 1124 /* All our frames have the CRC attached */
1125 m->m_flags |= M_HASFCS; 1125 m->m_flags |= M_HASFCS;
1126 if (m->m_pkthdr.len + pad > MHLEN ) 1126 if (m->m_pkthdr.len + pad > MHLEN) {
1127 MCLGET(m, M_DONTWAIT); 1127 MCLGET(m, M_DONTWAIT);
 1128 if ((m->m_flags & M_EXT) == 0) {
 1129 m_freem(m);
 1130 return NULL;
 1131 }
 1132 }
1128 1133
1129 m->m_data += pad; 1134 m->m_data += pad;
1130 m->m_len = frame_length + (frame_length % sc->sc_data_width); 1135 m->m_len = frame_length + (frame_length % sc->sc_data_width);
1131 1136
1132 return m; 1137 return m;
1133} 1138}