Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb Move uvideo's parsers into usbdi.c, to make them...



details:   https://anonhg.NetBSD.org/src/rev/8d499e9eb3ee
branches:  trunk
changeset: 744619:8d499e9eb3ee
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Feb 08 07:38:17 2020 +0000

description:
Move uvideo's parsers into usbdi.c, to make them global. Rename
usb_desc_iter_peek_next -> usb_desc_iter_peek for consistency.

diffstat:

 sys/dev/usb/usbdi.c  |  58 ++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/usb/usbdi.h  |   5 +++-
 sys/dev/usb/uvideo.c |  66 ++-------------------------------------------------
 3 files changed, 63 insertions(+), 66 deletions(-)

diffs (207 lines):

diff -r c15d3e0d908d -r 8d499e9eb3ee sys/dev/usb/usbdi.c
--- a/sys/dev/usb/usbdi.c       Sat Feb 08 07:24:46 2020 +0000
+++ b/sys/dev/usb/usbdi.c       Sat Feb 08 07:38:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.c,v 1.186 2019/08/28 01:44:39 mrg Exp $  */
+/*     $NetBSD: usbdi.c,v 1.187 2020/02/08 07:38:17 maxv Exp $ */
 
 /*
  * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.186 2019/08/28 01:44:39 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.187 2020/02/08 07:38:17 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1282,6 +1282,28 @@
 }
 
 const usb_descriptor_t *
+usb_desc_iter_peek(usbd_desc_iter_t *iter)
+{
+       const usb_descriptor_t *desc;
+
+       if (iter->cur + sizeof(usb_descriptor_t) >= iter->end) {
+               if (iter->cur != iter->end)
+                       printf("usb_desc_iter_peek_next: bad descriptor\n");
+               return NULL;
+       }
+       desc = (const usb_descriptor_t *)iter->cur;
+       if (desc->bLength == 0) {
+               printf("usb_desc_iter_peek_next: descriptor length = 0\n");
+               return NULL;
+       }
+       if (iter->cur + desc->bLength > iter->end) {
+               printf("usb_desc_iter_peek_next: descriptor length too large\n");
+               return NULL;
+       }
+       return desc;
+}
+
+const usb_descriptor_t *
 usb_desc_iter_next(usbd_desc_iter_t *iter)
 {
        const usb_descriptor_t *desc;
@@ -1304,6 +1326,38 @@
        return desc;
 }
 
+/* Return the next interface descriptor, skipping over any other
+ * descriptors.  Returns NULL at the end or on error. */
+const usb_interface_descriptor_t *
+usb_desc_iter_next_interface(usbd_desc_iter_t *iter)
+{
+       const usb_descriptor_t *desc;
+
+       while ((desc = usb_desc_iter_peek(iter)) != NULL &&
+              desc->bDescriptorType != UDESC_INTERFACE)
+       {
+               usb_desc_iter_next(iter);
+       }
+
+       return (const usb_interface_descriptor_t *)usb_desc_iter_next(iter);
+}
+
+/* Returns the next non-interface descriptor, returning NULL when the
+ * next descriptor would be an interface descriptor. */
+const usb_descriptor_t *
+usb_desc_iter_next_non_interface(usbd_desc_iter_t *iter)
+{
+       const usb_descriptor_t *desc;
+
+       if ((desc = usb_desc_iter_peek(iter)) != NULL &&
+           desc->bDescriptorType != UDESC_INTERFACE)
+       {
+               return usb_desc_iter_next(iter);
+       } else {
+               return NULL;
+       }
+}
+
 usbd_status
 usbd_get_string(struct usbd_device *dev, int si, char *buf)
 {
diff -r c15d3e0d908d -r 8d499e9eb3ee sys/dev/usb/usbdi.h
--- a/sys/dev/usb/usbdi.h       Sat Feb 08 07:24:46 2020 +0000
+++ b/sys/dev/usb/usbdi.h       Sat Feb 08 07:38:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usbdi.h,v 1.97 2019/08/28 01:44:39 mrg Exp $   */
+/*     $NetBSD: usbdi.h,v 1.98 2020/02/08 07:38:17 maxv Exp $  */
 /*     $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $      */
 
 /*
@@ -194,7 +194,10 @@
        const uByte *end;
 } usbd_desc_iter_t;
 void usb_desc_iter_init(struct usbd_device *, usbd_desc_iter_t *);
+const usb_descriptor_t *usb_desc_iter_peek(usbd_desc_iter_t *);
 const usb_descriptor_t *usb_desc_iter_next(usbd_desc_iter_t *);
+const usb_interface_descriptor_t *usb_desc_iter_next_interface(usbd_desc_iter_t *);
+const usb_descriptor_t *usb_desc_iter_next_non_interface(usbd_desc_iter_t *);
 
 /* Used to clear endpoint stalls from the softint */
 void usbd_clear_endpoint_stall_task(void *);
diff -r c15d3e0d908d -r 8d499e9eb3ee sys/dev/usb/uvideo.c
--- a/sys/dev/usb/uvideo.c      Sat Feb 08 07:24:46 2020 +0000
+++ b/sys/dev/usb/uvideo.c      Sat Feb 08 07:38:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvideo.c,v 1.53 2019/12/01 08:27:54 maxv Exp $ */
+/*     $NetBSD: uvideo.c,v 1.54 2020/02/08 07:38:17 maxv Exp $ */
 
 /*
  * Copyright (c) 2008 Patrick Mahoney
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.53 2019/12/01 08:27:54 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvideo.c,v 1.54 2020/02/08 07:38:17 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -361,12 +361,6 @@
 static void            uvideo_init_probe_data(uvideo_probe_and_commit_data_t *);
 
 
-static const usb_descriptor_t * usb_desc_iter_peek_next(usbd_desc_iter_t *);
-static const usb_interface_descriptor_t * usb_desc_iter_next_interface(
-       usbd_desc_iter_t *);
-static const usb_descriptor_t * usb_desc_iter_next_non_interface(
-       usbd_desc_iter_t *);
-
 static int     usb_guid_cmp(const usb_guid_t *, const guid_t *);
 
 
@@ -1330,7 +1324,7 @@
        /* Iterate through frame descriptors directly following the
         * format descriptor, and add a format to the format list for
         * each frame descriptor. */
-       while ((uvdesc = (const uvideo_descriptor_t *) usb_desc_iter_peek_next(iter)) &&
+       while ((uvdesc = (const uvideo_descriptor_t *)usb_desc_iter_peek(iter)) &&
               (uvdesc != NULL) && (uvdesc->bDescriptorSubtype == subtype))
        {
                uvdesc = (const uvideo_descriptor_t *) usb_desc_iter_next(iter);
@@ -2949,60 +2943,6 @@
 
 #endif /* !UVIDEO_DEBUG */
 
-static const usb_descriptor_t *
-usb_desc_iter_peek_next(usbd_desc_iter_t *iter)
-{
-        const usb_descriptor_t *desc;
-
-        if (iter->cur + sizeof(usb_descriptor_t) >= iter->end) {
-                if (iter->cur != iter->end)
-                        printf("usb_desc_iter_peek_next: bad descriptor\n");
-                return NULL;
-        }
-        desc = (const usb_descriptor_t *)iter->cur;
-        if (desc->bLength == 0) {
-                printf("usb_desc_iter_peek_next: descriptor length = 0\n");
-                return NULL;
-        }
-        if (iter->cur + desc->bLength > iter->end) {
-                printf("usb_desc_iter_peek_next: descriptor length too large\n");
-                return NULL;
-        }
-        return desc;
-}
-
-/* Return the next interface descriptor, skipping over any other
- * descriptors.  Returns NULL at the end or on error. */
-static const usb_interface_descriptor_t *
-usb_desc_iter_next_interface(usbd_desc_iter_t *iter)
-{
-       const usb_descriptor_t *desc;
-
-       while ((desc = usb_desc_iter_peek_next(iter)) != NULL &&
-              desc->bDescriptorType != UDESC_INTERFACE)
-       {
-               usb_desc_iter_next(iter);
-       }
-
-       return (const usb_interface_descriptor_t *)usb_desc_iter_next(iter);
-}
-
-/* Returns the next non-interface descriptor, returning NULL when the
- * next descriptor would be an interface descriptor. */
-static const usb_descriptor_t *
-usb_desc_iter_next_non_interface(usbd_desc_iter_t *iter)
-{
-       const usb_descriptor_t *desc;
-
-       if ((desc = usb_desc_iter_peek_next(iter)) != NULL &&
-           desc->bDescriptorType != UDESC_INTERFACE)
-       {
-               return usb_desc_iter_next(iter);
-       } else {
-               return NULL;
-       }
-}
-
 #ifdef UVIDEO_DEBUG
 static void
 usb_guid_print(const usb_guid_t *guid)



Home | Main Index | Thread Index | Old Index