NetBSD Problem Report #43820

From www@NetBSD.org  Mon Aug 30 20:24:02 2010
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 54B5D63B89F
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 30 Aug 2010 20:24:02 +0000 (UTC)
Message-Id: <20100830202401.E48C963B89A@www.NetBSD.org>
Date: Mon, 30 Aug 2010 20:24:01 +0000 (UTC)
From: sfisher@cradlepoint.com
Reply-To: sfisher@cradlepoint.com
To: gnats-bugs@NetBSD.org
Subject: usbd_device2interface_handle : returned iface could be ifaceno + 1
X-Send-Pr-Version: www-1.0

>Number:         43820
>Category:       kern
>Synopsis:       usbd_device2interface_handle : returned iface could be ifaceno + 1
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 30 20:25:00 +0000 2010
>Originator:     Shawn Fisher
>Release:        5.0.2
>Organization:
Cradlepoint
>Environment:
NetBSD  5.0.2 NetBSD 5.0.2 (XXX) #69: Mon Aug 30 13:57:03 MDT 2010
>Description:
usbd_device2interface_handle returns an index of the interface you want.  This usually works well until you run into a device that doesn't index the interfaces properly (sierra wireless).  An example would be a device that indexes the interfaces as 0,1,3,4,...N and asking for iface index 3, currently the function would return iface 4.  A fix would be to iterate through the ifaces stopping on the iface requested by ifaceno.
>How-To-Repeat:

>Fix:
Check the actual interface number against the number you are requesting.  Patch:

Index: sys/dev/usb/usbdi.c
===================================================================
--- sys/dev/usb/usbdi.c	(revision 2355)
+++ sys/dev/usb/usbdi.c	(working copy)
@@ -620,11 +620,25 @@
 usbd_device2interface_handle(usbd_device_handle dev,
 			     u_int8_t ifaceno, usbd_interface_handle *iface)
 {
+	u_int8_t niface;
+	usbd_status err;
+	int i;
+
 	if (dev->cdesc == NULL)
 		return (USBD_NOT_CONFIGURED);
 	if (ifaceno >= dev->cdesc->bNumInterface)
 		return (USBD_INVAL);
-	*iface = &dev->ifaces[ifaceno];
+	err = usbd_interface_count(dev, &niface);
+	if (err)
+		return (err);
+	for (i=0; i < niface; i++) {
+		if (dev->ifaces[i].idesc->bInterfaceNumber == ifaceno) {
+			*iface = &dev->ifaces[i];
+			goto found;
+		}
+	}
+	return (USBD_INVAL);
+found:
 	return (USBD_NORMAL_COMPLETION);
 }

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.