Discussion:
Use m_devget(9) in smsc(4)
(too old to reply)
Mark Kettenis
2016-07-30 20:03:33 UTC
Permalink
Removes a couple of lines of code from the driver.

ok?


Index: if_smsc.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_smsc.c,v
retrieving revision 1.27
diff -u -p -r1.27 if_smsc.c
--- if_smsc.c 13 Apr 2016 11:03:37 -0000 1.27
+++ if_smsc.c 30 Jul 2016 20:01:18 -0000
@@ -146,7 +146,6 @@ void smsc_init(void *);
void smsc_stop(struct smsc_softc *);
void smsc_start(struct ifnet *);
void smsc_reset(struct smsc_softc *);
-struct mbuf *smsc_newbuf(void);

void smsc_tick(void *);
void smsc_tick_task(void *);
@@ -1197,18 +1196,13 @@ smsc_rxeof(struct usbd_xfer *xfer, void
else
total_len -= pktlen;

- m = smsc_newbuf();
+ m = m_devget(buf, pktlen, ETHER_ALIGN);
if (m == NULL) {
- smsc_dbg_printf(sc, "smc_newbuf returned NULL\n");
+ smsc_dbg_printf(sc, "m_devget returned NULL\n");
ifp->if_ierrors++;
goto done;
}

- m->m_pkthdr.len = m->m_len = pktlen;
- m_adj(m, ETHER_ALIGN);
-
- memcpy(mtod(m, char *), buf, pktlen);
-
ml_enqueue(&ml, m);
} while (total_len > 0);

@@ -1328,24 +1322,6 @@ smsc_rx_list_init(struct smsc_softc *sc)
}

return (0);
-}
-
-struct mbuf *
-smsc_newbuf(void)
-{
- struct mbuf *m;
-
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL)
- return (NULL);
-
- MCLGET(m, M_DONTWAIT);
- if (!(m->m_flags & M_EXT)) {
- m_freem(m);
- return (NULL);
- }
-
- return (m);
}

int
Claudio Jeker
2016-07-31 11:55:31 UTC
Permalink
Post by Mark Kettenis
Removes a couple of lines of code from the driver.
ok?
This is the right use of m_devget. OK claudio@

PS: realized that the manpage for m_devget still has the old prototype
with the ifp in it...
--
:wq Claudio
Post by Mark Kettenis
Index: if_smsc.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_smsc.c,v
retrieving revision 1.27
diff -u -p -r1.27 if_smsc.c
--- if_smsc.c 13 Apr 2016 11:03:37 -0000 1.27
+++ if_smsc.c 30 Jul 2016 20:01:18 -0000
@@ -146,7 +146,6 @@ void smsc_init(void *);
void smsc_stop(struct smsc_softc *);
void smsc_start(struct ifnet *);
void smsc_reset(struct smsc_softc *);
-struct mbuf *smsc_newbuf(void);
void smsc_tick(void *);
void smsc_tick_task(void *);
@@ -1197,18 +1196,13 @@ smsc_rxeof(struct usbd_xfer *xfer, void
else
total_len -= pktlen;
- m = smsc_newbuf();
+ m = m_devget(buf, pktlen, ETHER_ALIGN);
if (m == NULL) {
- smsc_dbg_printf(sc, "smc_newbuf returned NULL\n");
+ smsc_dbg_printf(sc, "m_devget returned NULL\n");
ifp->if_ierrors++;
goto done;
}
- m->m_pkthdr.len = m->m_len = pktlen;
- m_adj(m, ETHER_ALIGN);
-
- memcpy(mtod(m, char *), buf, pktlen);
-
ml_enqueue(&ml, m);
} while (total_len > 0);
@@ -1328,24 +1322,6 @@ smsc_rx_list_init(struct smsc_softc *sc)
}
return (0);
-}
-
-struct mbuf *
-smsc_newbuf(void)
-{
- struct mbuf *m;
-
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL)
- return (NULL);
-
- MCLGET(m, M_DONTWAIT);
- if (!(m->m_flags & M_EXT)) {
- m_freem(m);
- return (NULL);
- }
-
- return (m);
}
int
Artturi Alm
2016-07-31 12:22:17 UTC
Permalink
Post by Claudio Jeker
Post by Mark Kettenis
Removes a couple of lines of code from the driver.
ok?
Another one. (2 dlg@, this was the m_*() i was looking for.)

-Artturi
Post by Claudio Jeker
PS: realized that the manpage for m_devget still has the old prototype
with the ifp in it...
--
:wq Claudio
Index: sxie.c
===================================================================
RCS file: /cvs/src/sys/arch/armv7/sunxi/sxie.c,v
retrieving revision 1.17
diff -u -p -r1.17 sxie.c
--- sxie.c 27 Jul 2016 11:45:02 -0000 1.17
+++ sxie.c 31 Jul 2016 12:12:44 -0000
@@ -179,7 +179,6 @@ void sxie_init(struct sxie_softc *);
void sxie_stop(struct sxie_softc *);
void sxie_reset(struct sxie_softc *);
void sxie_iff(struct sxie_softc *, struct ifnet *);
-struct mbuf * sxie_newbuf(void);
int sxie_intr(void *);
void sxie_recv(struct sxie_softc *);
int sxie_miibus_readreg(struct device *, int, int);
@@ -607,10 +606,6 @@ trynext:
goto err_out;
}

- m = sxie_newbuf();
- if (m == NULL)
- goto err_out;
-
reg = SXIREAD4(sc, SXIE_RXIO);
pktstat = (uint16_t)reg >> 16;
pktlen = (int16_t)reg; /* length of useful data */
@@ -622,10 +617,6 @@ trynext:
if (pktlen > SXIE_MAX_PKT_SIZE)
pktlen = SXIE_MAX_PKT_SIZE; /* XXX is truncating ok? */

- m->m_pkthdr.len = m->m_len = pktlen;
- /* XXX m->m_pkthdr.csum_flags ? */
- m_adj(m, ETHER_ALIGN);
-
/* read the actual packet from fifo XXX through 'align buffer'.. */
if (pktlen & 3)
rlen = SXIE_ROUNDUP(pktlen, 4);
@@ -633,7 +624,12 @@ trynext:
rlen = pktlen;
bus_space_read_multi_4(sc->sc_iot, sc->sc_ioh,
SXIE_RXIO, (uint32_t *)&rxbuf[0], rlen >> 2);
- memcpy(mtod(m, char *), (char *)&rxbuf[0], pktlen);
+
+ m = m_devget(&rxbuf[0], pktlen, ETHER_ALIGN);
+ if (m == NULL) {
+ ifp->if_ierrors++;
+ goto err_out;
+ }

ml_enqueue(&ml, m);
goto trynext;
@@ -683,24 +679,6 @@ sxie_ioctl(struct ifnet *ifp, u_long cmd

splx(s);
return error;
-}
-
-struct mbuf *
-sxie_newbuf(void)
-{
- struct mbuf *m;
-
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL)
- return (NULL);
-
- MCLGET(m, M_DONTWAIT);
- if (!(m->m_flags & M_EXT)) {
- m_freem(m);
- return (NULL);
- }
-
- return (m);
}

void

Loading...