Re: USB: EHCI Debug Port Device Gadget

From: Geert Uytterhoeven
Date: Thu Aug 12 2010 - 17:38:44 EST


On Wed, Aug 11, 2010 at 01:00, Linux Kernel Mailing List
<linux-kernel@xxxxxxxxxxxxxxx> wrote:
> Gitweb: Â Â http://git.kernel.org/linus/f6c826a90055dd05905982f7a3f60e0bcaa0434e

> Â ÂUSB: EHCI Debug Port Device Gadget

> diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
> new file mode 100644
> index 0000000..0ed50a2
> --- /dev/null
> +++ b/drivers/usb/gadget/dbgp.c

> +static int dbgp_setup(struct usb_gadget *gadget,
> + Â Â Â Â Â Â Â Â Â Â const struct usb_ctrlrequest *ctrl)
> +{
> + Â Â Â struct usb_request *req = dbgp.req;
> + Â Â Â u8 request = ctrl->bRequest;
> + Â Â Â u16 value = le16_to_cpu(ctrl->wValue);
> + Â Â Â u16 length = le16_to_cpu(ctrl->wLength);
> + Â Â Â int err = 0;
> + Â Â Â void *data;
> + Â Â Â u16 len;
> +
> + Â Â Â gadget->ep0->driver_data = gadget;
> +
> + Â Â Â if (request == USB_REQ_GET_DESCRIPTOR) {
> + Â Â Â Â Â Â Â switch (value>>8) {
> + Â Â Â Â Â Â Â case USB_DT_DEVICE:
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(&dbgp.gadget->dev, "setup: desc device\n");
> + Â Â Â Â Â Â Â Â Â Â Â len = sizeof device_desc;
> + Â Â Â Â Â Â Â Â Â Â Â data = &device_desc;
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â case USB_DT_DEBUG:
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(&dbgp.gadget->dev, "setup: desc debug\n");
> + Â Â Â Â Â Â Â Â Â Â Â len = sizeof dbg_desc;
> + Â Â Â Â Â Â Â Â Â Â Â data = &dbg_desc;
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â default:
> + Â Â Â Â Â Â Â Â Â Â Â goto fail;
> + Â Â Â Â Â Â Â }
> + Â Â Â } else if (request == USB_REQ_SET_FEATURE &&
> + Â Â Â Â Â Â Â Â Âvalue == USB_DEVICE_DEBUG_MODE) {
> + Â Â Â Â Â Â Â len = 0;
> + Â Â Â Â Â Â Â data = NULL;
> + Â Â Â Â Â Â Â dev_dbg(&dbgp.gadget->dev, "setup: feat debug\n");
> +#ifdef CONFIG_USB_G_DBGP_PRINTK
> + Â Â Â Â Â Â Â err = dbgp_enable_ep();
> +#else
> + Â Â Â Â Â Â Â err = gserial_connect(dbgp.serial, 0);
> +#endif
> + Â Â Â Â Â Â Â if (err < 0)
> + Â Â Â Â Â Â Â Â Â Â Â goto fail;
> + Â Â Â } else
> + Â Â Â Â Â Â Â goto fail;
> +
> + Â Â Â if (len >= 0) {

warning: comparison is always true due to limited range of data type

len is u16. Perhaps the test was intended to be `(len > 0)'?

> + Â Â Â Â Â Â Â req->length = min(length, len);
> + Â Â Â Â Â Â Â req->zero = len < req->length;
> + Â Â Â Â Â Â Â if (data && req->length)
> + Â Â Â Â Â Â Â Â Â Â Â memcpy(req->buf, data, req->length);
> +
> + Â Â Â Â Â Â Â req->complete = dbgp_setup_complete;
> + Â Â Â Â Â Â Â return usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
> + Â Â Â }
> +
> +fail:
> + Â Â Â dev_dbg(&dbgp.gadget->dev,
> + Â Â Â Â Â Â Â "setup: failure req %x v %x\n", request, value);
> + Â Â Â return err;
> +}
> +
> +static struct usb_gadget_driver dbgp_driver = {
> + Â Â Â .function = "dbgp",
> + Â Â Â .speed = USB_SPEED_HIGH,
> + Â Â Â .bind = dbgp_bind,
> + Â Â Â .unbind = dbgp_unbind,
> + Â Â Â .setup = dbgp_setup,
> + Â Â Â .disconnect = dbgp_disconnect,
> + Â Â Â .driver = {
> + Â Â Â Â Â Â Â .owner = THIS_MODULE,
> + Â Â Â Â Â Â Â .name = "dbgp"
> + Â Â Â },
> +};
> +
> +static int __init dbgp_init(void)
> +{
> + Â Â Â return usb_gadget_register_driver(&dbgp_driver);
> +}
> +
> +static void __exit dbgp_exit(void)
> +{
> + Â Â Â usb_gadget_unregister_driver(&dbgp_driver);
> +#ifdef CONFIG_USB_G_DBGP_SERIAL
> + Â Â Â gserial_cleanup();
> +#endif
> +}
> +
> +MODULE_AUTHOR("Stephane Duverger");
> +MODULE_LICENSE("GPL");
> +module_init(dbgp_init);
> +module_exit(dbgp_exit);
> --
> To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>



--
Gr{oetje,eeting}s,

            Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
             Â Â -- Linus Torvalds
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i