diff mbox

usb: otg: isp1301_omap: fix potential NULL pointer dereference

Message ID CAPgLHd-21EJ3CMaFVzckj8=iZdBXW=rthttTnseNrfoH+aCcAA@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Yongjun Oct. 8, 2012, 12:46 a.m. UTC
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

The dereference should be moved below the NULL test.

dpatch engine is used to auto generate this patch.
(https://github.com/weiyj/dpatch)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/usb/otg/isp1301_omap.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index ceee211..3a1f8e2 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -1279,9 +1279,13 @@  static int isp1301_otg_enable(struct isp1301 *isp)
 static int
 isp1301_set_host(struct usb_otg *otg, struct usb_bus *host)
 {
-	struct isp1301	*isp = container_of(otg->phy, struct isp1301, phy);
+	struct isp1301 *isp;
 
-	if (!otg || isp != the_transceiver)
+	if (!otg)
+		return -ENODEV;
+
+	isp = container_of(otg->phy, struct isp1301, phy);
+	if (isp != the_transceiver)
 		return -ENODEV;
 
 	if (!host) {
@@ -1335,9 +1339,13 @@  isp1301_set_host(struct usb_otg *otg, struct usb_bus *host)
 static int
 isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
 {
-	struct isp1301	*isp = container_of(otg->phy, struct isp1301, phy);
+	struct isp1301 *isp;
+
+	if (!otg)
+		return -ENODEV;
 
-	if (!otg || isp != the_transceiver)
+	isp = container_of(otg->phy, struct isp1301, phy);
+	if (isp != the_transceiver)
 		return -ENODEV;
 
 	if (!gadget) {
@@ -1415,11 +1423,14 @@  isp1301_set_power(struct usb_phy *dev, unsigned mA)
 static int
 isp1301_start_srp(struct usb_otg *otg)
 {
-	struct isp1301	*isp = container_of(otg->phy, struct isp1301, phy);
+	struct isp1301	*isp;
 	u32		otg_ctrl;
 
-	if (!otg || isp != the_transceiver
-			|| isp->phy.state != OTG_STATE_B_IDLE)
+	if (!otg)
+		return -ENODEV;
+
+	isp = container_of(otg->phy, struct isp1301, phy);
+	if (isp != the_transceiver || isp->phy.state != OTG_STATE_B_IDLE)
 		return -ENODEV;
 
 	otg_ctrl = omap_readl(OTG_CTRL);
@@ -1443,10 +1454,13 @@  static int
 isp1301_start_hnp(struct usb_otg *otg)
 {
 #ifdef	CONFIG_USB_OTG
-	struct isp1301	*isp = container_of(otg->phy, struct isp1301, phy);
+	struct isp1301 *isp;
 	u32 l;
 
-	if (!otg || isp != the_transceiver)
+	if (!otg)
+		return -ENODEV;
+	isp = container_of(otg->phy, struct isp1301, phy);
+	if (isp != the_transceiver)
 		return -ENODEV;
 	if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable))
 		return -ENOTCONN;