[PATCH] usb: gadget: mv_udc: fix potential register access when clock off

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

 



The Android gadget has sysfs interface to configure usb gadget.
And it may access udc driver when there is no cable attached.
That is too say, the udc controller may in clock off status.
It will cause system hang when access udc controller's register at this
time.

Change-Id: Ib8783b725f5f57323499d23bc891c6f9a07b5e8d
Signed-off-by: Neil Zhang <zhangwm@xxxxxxxxxxx>
---
 drivers/usb/gadget/mv_udc_core.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index 771ef45..067cf65 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -594,6 +594,9 @@ static int  mv_ep_disable(struct usb_ep *_ep)
 
 	udc = ep->udc;
 
+	if (!udc->active)
+		return 0;
+
 	/* Get the endpoint queue head address */
 	dqh = ep->dqh;
 
@@ -839,6 +842,9 @@ static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	if (!_ep || !_req)
 		return -EINVAL;
 
+	if (!udc->active)
+		return 0;
+
 	spin_lock_irqsave(&ep->udc->lock, flags);
 	stopped = ep->stopped;
 
@@ -2333,6 +2339,11 @@ usb_reg_show(struct device *dev, struct device_attribute *attr, char *buf)
 		return -1;
 	}
 
+	if (!udc->active) {
+		ret = sprintf(buf, "The controller is clock off now.\n");
+		return ret;
+	}
+
 	ret = sprintf(buf, "usbcmd: 0x%x\n",
 			readl(&udc->op_regs->usbcmd));
 	ret += sprintf(buf + ret, "usbsts: 0x%x\n",
@@ -2365,7 +2376,6 @@ usb_reg_show(struct device *dev, struct device_attribute *attr, char *buf)
 	for (i = 0; i < 16; i++)
 		ret += sprintf(buf + ret, "epctrlx[%d]: 0x%x\n",
 			i, readl(&udc->op_regs->epctrlx[i]));
-
 	return ret;
 }
 
-- 
1.7.4.1

--
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