forked from mirrors/linux
		
	usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()
If 'ep' is NULL, result of ep_to_cdns3_ep(ep) is invalid pointer
and its dereference with priv_ep->cdns3_dev may cause panic.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 7733f6c32e ("usb: cdns3: Add Cadence USB3 DRD Driver")
Acked-by: Peter Chen <peter.chen@kernel.org>
Signed-off-by: Andrey Strachuk <strochuk@ispras.ru>
Link: https://lore.kernel.org/r/20220718160052.4188-1-strochuk@ispras.ru
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
			
			
This commit is contained in:
		
							parent
							
								
									fe3cc0cebe
								
							
						
					
					
						commit
						c3ffc9c4ca
					
				
					 1 changed files with 6 additions and 3 deletions
				
			
		|  | @ -2285,14 +2285,15 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, | ||||||
| 	int val; | 	int val; | ||||||
| 
 | 
 | ||||||
| 	priv_ep = ep_to_cdns3_ep(ep); | 	priv_ep = ep_to_cdns3_ep(ep); | ||||||
| 	priv_dev = priv_ep->cdns3_dev; |  | ||||||
| 	comp_desc = priv_ep->endpoint.comp_desc; |  | ||||||
| 
 | 
 | ||||||
| 	if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { | 	if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { | ||||||
| 		dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); | 		dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	comp_desc = priv_ep->endpoint.comp_desc; | ||||||
|  | 	priv_dev = priv_ep->cdns3_dev; | ||||||
|  | 
 | ||||||
| 	if (!desc->wMaxPacketSize) { | 	if (!desc->wMaxPacketSize) { | ||||||
| 		dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); | 		dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
|  | @ -2600,7 +2601,7 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep, | ||||||
| 			    struct usb_request *request) | 			    struct usb_request *request) | ||||||
| { | { | ||||||
| 	struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); | 	struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); | ||||||
| 	struct cdns3_device *priv_dev = priv_ep->cdns3_dev; | 	struct cdns3_device *priv_dev; | ||||||
| 	struct usb_request *req, *req_temp; | 	struct usb_request *req, *req_temp; | ||||||
| 	struct cdns3_request *priv_req; | 	struct cdns3_request *priv_req; | ||||||
| 	struct cdns3_trb *link_trb; | 	struct cdns3_trb *link_trb; | ||||||
|  | @ -2611,6 +2612,8 @@ int cdns3_gadget_ep_dequeue(struct usb_ep *ep, | ||||||
| 	if (!ep || !request || !ep->desc) | 	if (!ep || !request || !ep->desc) | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
| 
 | 
 | ||||||
|  | 	priv_dev = priv_ep->cdns3_dev; | ||||||
|  | 
 | ||||||
| 	spin_lock_irqsave(&priv_dev->lock, flags); | 	spin_lock_irqsave(&priv_dev->lock, flags); | ||||||
| 
 | 
 | ||||||
| 	priv_req = to_cdns3_request(request); | 	priv_req = to_cdns3_request(request); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Andrey Strachuk
						Andrey Strachuk