[PATCH] usb: usbip: fix null pointer dereference

From: Sudip Mukherjee
Date: Thu Jun 02 2016 - 13:52:55 EST


We have been dereferencing udc before checking it. Lets use it after it
has been checked.

Signed-off-by: Sudip Mukherjee <sudip.mukherjee@xxxxxxxxxxxxxxx>
---
drivers/usb/usbip/vudc_sysfs.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c
index 99397fa..0ba6a06 100644
--- a/drivers/usb/usbip/vudc_sysfs.c
+++ b/drivers/usb/usbip/vudc_sysfs.c
@@ -35,14 +35,17 @@
int get_gadget_descs(struct vudc *udc)
{
struct vrequest *usb_req;
- struct vep *ep0 = to_vep(udc->gadget.ep0);
- struct usb_device_descriptor *ddesc = &udc->dev_desc;
+ struct vep *ep0;
+ struct usb_device_descriptor *ddesc;
struct usb_ctrlrequest req;
int ret;

if (!udc || !udc->driver || !udc->pullup)
return -EINVAL;

+ ep0 = to_vep(udc->gadget.ep0);
+ ddesc = &udc->dev_desc;
+
req.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
req.bRequest = USB_REQ_GET_DESCRIPTOR;
req.wValue = cpu_to_le16(USB_DT_DEVICE << 8);
--
1.9.1