Re: [PATCH] usb gadget: fix null pointer dereference

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

 



On 08/16/2011 06:38 PM, Sebastian Andrzej Siewior wrote:
* Yang Ruirui | 2011-08-16 18:01:54 [+0800]:

diff -uprN a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
--- a/drivers/usb/gadget/composite.c	2011-08-16 17:49:38.813038094 +0800
+++ b/drivers/usb/gadget/composite.c	2011-08-16 17:47:03.716372207 +0800
@@ -603,6 +603,7 @@ static int set_config(struct usb_composi
	int			result = -EINVAL;
	unsigned		power = gadget_is_otg(gadget) ? 8 : 100;
	int			tmp;
+	enum usb_device_speed	s = USB_SPEED_LOW;

	if (number) {
		list_for_each_entry(c,&cdev->configs, list) {
@@ -626,6 +627,14 @@ static int set_config(struct usb_composi
		result = 0;
	}

+	if (c->fullspeed&&  (gadget->speed == USB_SPEED_FULL))
+		s = USB_SPEED_FULL;
+	if (c->highspeed&&  (gadget->speed == USB_SPEED_HIGH))
+		s = USB_SPEED_HIGH;
+	if (c->superspeed&&  (gadget->speed == USB_SPEED_SUPER))
+		s = USB_SPEED_SUPER;
+	gadget->speed = s;
+

I'm not sure if this is the right way. After all the speed is still HS
we just use FS descriptors. And I'm not sure if changing the speed is a
wise thing to do.
Is this a regression from recent changes in the framework?

What about config_ep_by_speed(), config_buf(), set_config() not assigned
a null pointer in the first place?

Sebastian

Following patch also fix my problem, anyone can explain a bit about the comment?
Where to set the CONFIG_USB_GADGET_DUALSPEED?
In my case musb gadget set is_dualspeed to 1, but gadget_is_dualspeed return 0,
so hs_descriptors is not copied.

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 087f4b9..d9b5bdb 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -548,14 +548,7 @@ static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
  */
 static inline int gadget_is_dualspeed(struct usb_gadget *g)
 {
-#ifdef CONFIG_USB_GADGET_DUALSPEED
-   /* runtime test would check "g->is_dualspeed" ... that might be
-    * useful to work around hardware bugs, but is mostly pointless
-    */
-   return 1;
-#else
-   return 0;
-#endif
+ return g->is_dualspeed;
 }
/**



--
Thanks
Yang Ruirui
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux