diff options
| -rw-r--r-- | sys/dev/usb/net/if_cdce.c | 5 | ||||
| -rw-r--r-- | sys/dev/usb/net/usb_ethernet.c | 19 | ||||
| -rw-r--r-- | sys/dev/usb/net/usb_ethernet.h | 1 |
3 files changed, 18 insertions, 7 deletions
diff --git a/sys/dev/usb/net/if_cdce.c b/sys/dev/usb/net/if_cdce.c index 42df55380e8b2..a54ddc0abc944 100644 --- a/sys/dev/usb/net/if_cdce.c +++ b/sys/dev/usb/net/if_cdce.c @@ -665,13 +665,10 @@ cdce_bulk_read_callback(struct usb2_xfer *xfer) */ for (x = 0; x != 1; x++) { if (sc->sc_rx_buf[x] == NULL) { - m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + m = usb2_ether_newbuf(); if (m == NULL) goto tr_stall; sc->sc_rx_buf[x] = m; - /* adjust for ethernet */ - m->m_len = m->m_pkthdr.len = MCLBYTES; - m_adj(m, ETHER_ALIGN); } else { m = sc->sc_rx_buf[x]; } diff --git a/sys/dev/usb/net/usb_ethernet.c b/sys/dev/usb/net/usb_ethernet.c index ac4b70153fe73..80b8852e8eb22 100644 --- a/sys/dev/usb/net/usb_ethernet.c +++ b/sys/dev/usb/net/usb_ethernet.c @@ -512,6 +512,20 @@ static moduledata_t usb2_ether_mod = { 0 }; +struct mbuf * +usb2_ether_newbuf(void) +{ + struct mbuf *m_new; + + m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + if (m_new == NULL) + return (NULL); + m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; + + m_adj(m_new, ETHER_ALIGN); + return (m_new); +} + int usb2_ether_rxmbuf(struct usb2_ether *ue, struct mbuf *m, unsigned int len) @@ -539,16 +553,15 @@ usb2_ether_rxbuf(struct usb2_ether *ue, struct usb2_page_cache *pc, UE_LOCK_ASSERT(ue, MA_OWNED); - if (len < ETHER_HDR_LEN || len > MCLBYTES) + if (len < ETHER_HDR_LEN || len > MCLBYTES - ETHER_ALIGN) return (1); - m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR); + m = usb2_ether_newbuf(); if (m == NULL) { ifp->if_ierrors++; return (ENOMEM); } - m_adj(m, ETHER_ALIGN); usb2_copy_out(pc, offset, mtod(m, uint8_t *), len); /* finalize mbuf */ diff --git a/sys/dev/usb/net/usb_ethernet.h b/sys/dev/usb/net/usb_ethernet.h index 0ee36f2bec440..3f45e6f7c02a6 100644 --- a/sys/dev/usb/net/usb_ethernet.h +++ b/sys/dev/usb/net/usb_ethernet.h @@ -111,6 +111,7 @@ void *usb2_ether_getsc(struct usb2_ether *); int usb2_ether_ifattach(struct usb2_ether *); void usb2_ether_ifdetach(struct usb2_ether *); int usb2_ether_ioctl(struct ifnet *, u_long, caddr_t); +struct mbuf *usb2_ether_newbuf(void); int usb2_ether_rxmbuf(struct usb2_ether *, struct mbuf *, unsigned int); int usb2_ether_rxbuf(struct usb2_ether *, |
