Commit 58add6ca authored by Wei Yongjun's avatar Wei Yongjun Committed by Felipe Balbi

usb: otg: move the dereference below the NULL test

The dereference should be moved below the NULL test.

spatch with a semantic match is used to found this.
(http://coccinelle.lip6.fr/)
Signed-off-by: default avatarWei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent c9e4412a
...@@ -544,9 +544,13 @@ int fsl_otg_start_gadget(struct otg_fsm *fsm, int on) ...@@ -544,9 +544,13 @@ int fsl_otg_start_gadget(struct otg_fsm *fsm, int on)
*/ */
static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host) static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
{ {
struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); struct fsl_otg *otg_dev;
if (!otg)
return -ENODEV;
if (!otg || otg_dev != fsl_otg_dev) otg_dev = container_of(otg->phy, struct fsl_otg, phy);
if (otg_dev != fsl_otg_dev)
return -ENODEV; return -ENODEV;
otg->host = host; otg->host = host;
...@@ -590,12 +594,15 @@ static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host) ...@@ -590,12 +594,15 @@ static int fsl_otg_set_host(struct usb_otg *otg, struct usb_bus *host)
static int fsl_otg_set_peripheral(struct usb_otg *otg, static int fsl_otg_set_peripheral(struct usb_otg *otg,
struct usb_gadget *gadget) struct usb_gadget *gadget)
{ {
struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); struct fsl_otg *otg_dev;
if (!otg)
return -ENODEV;
otg_dev = container_of(otg->phy, struct fsl_otg, phy);
VDBG("otg_dev 0x%x\n", (int)otg_dev); VDBG("otg_dev 0x%x\n", (int)otg_dev);
VDBG("fsl_otg_dev 0x%x\n", (int)fsl_otg_dev); VDBG("fsl_otg_dev 0x%x\n", (int)fsl_otg_dev);
if (otg_dev != fsl_otg_dev)
if (!otg || otg_dev != fsl_otg_dev)
return -ENODEV; return -ENODEV;
if (!gadget) { if (!gadget) {
...@@ -660,10 +667,13 @@ static void fsl_otg_event(struct work_struct *work) ...@@ -660,10 +667,13 @@ static void fsl_otg_event(struct work_struct *work)
/* B-device start SRP */ /* B-device start SRP */
static int fsl_otg_start_srp(struct usb_otg *otg) static int fsl_otg_start_srp(struct usb_otg *otg)
{ {
struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); struct fsl_otg *otg_dev;
if (!otg || otg->phy->state != OTG_STATE_B_IDLE)
return -ENODEV;
if (!otg || otg_dev != fsl_otg_dev otg_dev = container_of(otg->phy, struct fsl_otg, phy);
|| otg->phy->state != OTG_STATE_B_IDLE) if (otg_dev != fsl_otg_dev)
return -ENODEV; return -ENODEV;
otg_dev->fsm.b_bus_req = 1; otg_dev->fsm.b_bus_req = 1;
...@@ -675,9 +685,13 @@ static int fsl_otg_start_srp(struct usb_otg *otg) ...@@ -675,9 +685,13 @@ static int fsl_otg_start_srp(struct usb_otg *otg)
/* A_host suspend will call this function to start hnp */ /* A_host suspend will call this function to start hnp */
static int fsl_otg_start_hnp(struct usb_otg *otg) static int fsl_otg_start_hnp(struct usb_otg *otg)
{ {
struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); struct fsl_otg *otg_dev;
if (!otg)
return -ENODEV;
if (!otg || otg_dev != fsl_otg_dev) otg_dev = container_of(otg->phy, struct fsl_otg, phy);
if (otg_dev != fsl_otg_dev)
return -ENODEV; return -ENODEV;
DBG("start_hnp...n"); DBG("start_hnp...n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment