On Thu, 4 Mar 2004, Ullrich Sigwanz wrote:
> Hello,
>
> After compiling a new 2.6 kernel my Hewlett Packard Scanner 4300C was no
> longer detected.
> The console output was usb_control/bulk_msg: timeout
>
> I investigated the source code (and some posts) and found a difference in
> the file of 2.6 compared to 2.4
>
> In 2.4.21 drivers/usb/usb.c line 2157 was:
> err = usb_get_string(dev, dev->string_langid, index, tbuf, 255);
>
> Now in 2.6.0 drivers/usb/core/message.c line 1208:
> err = usb_get_string(dev, dev->string_langid, index, tbuf, len);
>
> after setting to parameter len = 255 the device worked right away.
>
> My scanner apparently reports the string descriptor length incorrectly,
> which leads to a global denial of the whole device.
This patch does essentially what you asked (it uses 256 instead of 255).
Requesting 256 bytes instead of the actual length of the string should not
involve any significant extra overhead, since the device will only
transmit the actual string contents.
In addition, the patch requests a full maxpacket-sized buffer when
retrieving the list of languages, to prevent the possibility of a babble
error. This is in line with the policy recommended by Martin Diehl.
If there are no objections, I think this should be applied.
Alan Stern
===== message.c 1.72 vs edited =====
--- 1.72/drivers/usb/core/message.c Wed Mar 3 15:47:37 2004
+++ edited/drivers/usb/core/message.c Thu Mar 4 12:06:35 2004
@@ -1219,19 +1219,20 @@
int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
{
unsigned char *tbuf;
- int err, len;
+ int err;
unsigned int u, idx;
+#define TBUFSIZE 256
if (size <= 0 || !buf || !index)
return -EINVAL;
buf[0] = 0;
- tbuf = kmalloc(256, GFP_KERNEL);
+ tbuf = kmalloc(TBUFSIZE, GFP_KERNEL);
if (!tbuf)
return -ENOMEM;
/* get langid for strings if it's not yet known */
if (!dev->have_langid) {
- err = usb_get_string(dev, 0, 0, tbuf, 4);
+ err = usb_get_string(dev, 0, 0, tbuf, dev->epmaxpacketin[0]);
if (err < 0) {
err("error getting string descriptor 0 (error=%d)", err);
goto errout;
@@ -1247,17 +1248,8 @@
dev->devnum, dev->string_langid);
}
}
-
- /*
- * ask for the length of the string
- */
-
- err = usb_get_string(dev, dev->string_langid, index, tbuf, 2);
- if(err<2)
- goto errout;
- len=tbuf[0];
- err = usb_get_string(dev, dev->string_langid, index, tbuf, len);
+ err = usb_get_string(dev, dev->string_langid, index, tbuf, TBUFSIZE);
if (err < 0)
goto errout;
@@ -1276,6 +1268,7 @@
errout:
kfree(tbuf);
return err;
+#undef TBUFSIZE
}
// synchronous request completion model
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel