Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jul 2006 07:27:03 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 102112 for review
Message-ID:  <200607220727.k6M7R3F7003027@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=102112

Change 102112 by hselasky@hselasky_mini_itx on 2006/07/22 07:26:22

	Factorize "usbd_m_copy_in" into using "m_apply()".

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb/usb_subr.c#9 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb/usb_subr.c#9 (text+ko) ====

@@ -1681,39 +1681,30 @@
 	return;
 }
 
-
 /*---------------------------------------------------------------------------*
- *  usbd_m_copy_in - copy a mbuf chain directly to DMA-able memory
+ *  usbd_m_copy_in - copy a mbuf chain directly into DMA-able memory
  *---------------------------------------------------------------------------*/
+struct usbd_m_copy_in_arg {
+	struct usbd_page_cache *cache;
+	u_int32_t dst_offset;
+};
+
+static int32_t
+usbd_m_copy_in_cb(void *arg, void *src, u_int32_t count)
+{
+	register struct usbd_m_copy_in_arg *ua = arg;
+	usbd_copy_in(ua->cache, ua->dst_offset, src, count);
+	ua->dst_offset += count;
+	return 0;
+}
+
 void
 usbd_m_copy_in(struct usbd_page_cache *cache, u_int32_t dst_offset,
 	       struct mbuf *m, u_int32_t src_offset, u_int32_t src_len)
 {
-	u_int32_t count;
-  
-	while (src_offset > 0) {
-	    __KASSERT(m != NULL, ("usbd_m_copy_in, offset > "
-				  "size of mbuf chain"));
-	    if (src_offset < m->m_len) {
-	        break;
-	    }
-	    src_offset -= m->m_len;
-	    m = m->m_next;
-	}
-
-	while (src_len > 0) {
-	    __KASSERT(m != NULL, ("usbd_m_copy_in, length > "
-				  "size of mbuf chain"));
-	    count = min(m->m_len - src_offset, src_len);
-
-	    usbd_copy_in(cache, dst_offset, ((caddr_t)(m->m_data)) + 
-			 src_offset, count);
-
-	    src_len -= count;
-	    dst_offset += count;
-	    src_offset = 0;
-	    m = m->m_next;
-	}
+	struct usbd_m_copy_in_arg arg = { cache, dst_offset };
+	register int error;
+	error = m_apply(m, src_offset, src_len, &usbd_m_copy_in_cb, &arg);
 	return;
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607220727.k6M7R3F7003027>