[PATCH 2/7] USB: gadget: composite: avoid possible NULL ptr dereference

Lucas Stach dev at lynxeye.de
Wed Jul 6 11:44:35 PDT 2016


Check if g is valid before trying to dereference it.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/usb/gadget/composite.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 9e38ac4..1cfc49d 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -86,7 +86,7 @@ int config_ep_by_speed(struct usb_gadget *g,
 			struct usb_function *f,
 			struct usb_ep *_ep)
 {
-	struct usb_composite_dev	*cdev = get_gadget_data(g);
+	struct usb_composite_dev *cdev;
 	struct usb_endpoint_descriptor *chosen_desc = NULL;
 	struct usb_descriptor_header **speed_desc = NULL;
 
@@ -98,6 +98,8 @@ int config_ep_by_speed(struct usb_gadget *g,
 	if (!g || !f || !_ep)
 		return -EIO;
 
+	cdev = get_gadget_data(g);
+
 	/* select desired speed */
 	switch (g->speed) {
 	case USB_SPEED_SUPER:
-- 
2.7.4




More information about the barebox mailing list