diff mbox

[v2,1/3] usb: musb: Handle nullpointer

Message ID 1381758639-30300-2-git-send-email-mpa@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Markus Pargmann Oct. 14, 2013, 1:50 p.m. UTC
When the device is connected to a host without a gadget driver,
otg->gadget is NULL.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 drivers/usb/musb/musb_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Felipe Balbi Oct. 14, 2013, 10:49 p.m. UTC | #1
On Mon, Oct 14, 2013 at 03:50:37PM +0200, Markus Pargmann wrote:
> When the device is connected to a host without a gadget driver,
> otg->gadget is NULL.
> 
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> ---
>  drivers/usb/musb/musb_core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index 18e877f..baa4f6a 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
>  				break;
>  		case OTG_STATE_B_PERIPHERAL:

why would we be in B peripheral if we're host only ? Bug seems to be
else where.
Bin Liu Oct. 15, 2013, 1:56 a.m. UTC | #2
On Mon, Oct 14, 2013 at 5:49 PM, Felipe Balbi <balbi@ti.com> wrote:
> On Mon, Oct 14, 2013 at 03:50:37PM +0200, Markus Pargmann wrote:
>> When the device is connected to a host without a gadget driver,
>> otg->gadget is NULL.
>>
>> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
>> ---
>>  drivers/usb/musb/musb_core.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
>> index 18e877f..baa4f6a 100644
>> --- a/drivers/usb/musb/musb_core.c
>> +++ b/drivers/usb/musb/musb_core.c
>> @@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
>>                               break;
>>               case OTG_STATE_B_PERIPHERAL:
>
> why would we be in B peripheral if we're host only ? Bug seems to be
> else where.

We are not host, we are in device mode.

But I would think the proper fix should be not setting
DEVCTL[SOFTCONN] until a gadget driver is loaded. Then the host will
not see the device which does not have a gadget driver.

Regards,
-Bin.

>
> --
> balbi
Bin Liu Oct. 15, 2013, 2 a.m. UTC | #3
On Mon, Oct 14, 2013 at 8:56 PM, Bin Liu <binmlist@gmail.com> wrote:
> On Mon, Oct 14, 2013 at 5:49 PM, Felipe Balbi <balbi@ti.com> wrote:
>> On Mon, Oct 14, 2013 at 03:50:37PM +0200, Markus Pargmann wrote:
>>> When the device is connected to a host without a gadget driver,
>>> otg->gadget is NULL.
>>>
>>> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
>>> ---
>>>  drivers/usb/musb/musb_core.c | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
>>> index 18e877f..baa4f6a 100644
>>> --- a/drivers/usb/musb/musb_core.c
>>> +++ b/drivers/usb/musb/musb_core.c
>>> @@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
>>>                               break;
>>>               case OTG_STATE_B_PERIPHERAL:
>>
>> why would we be in B peripheral if we're host only ? Bug seems to be
>> else where.
>
> We are not host, we are in device mode.
>
> But I would think the proper fix should be not setting
> DEVCTL[SOFTCONN] until a gadget driver is loaded. Then the host will
> not see the device which does not have a gadget driver.

Sorry, I meant POWER[SOFTCONN] bit.

>
> Regards,
> -Bin.
>
>>
>> --
>> balbi
Felipe Balbi Oct. 15, 2013, 3:07 a.m. UTC | #4
On Mon, Oct 14, 2013 at 09:00:33PM -0500, Bin Liu wrote:
> On Mon, Oct 14, 2013 at 8:56 PM, Bin Liu <binmlist@gmail.com> wrote:
> > On Mon, Oct 14, 2013 at 5:49 PM, Felipe Balbi <balbi@ti.com> wrote:
> >> On Mon, Oct 14, 2013 at 03:50:37PM +0200, Markus Pargmann wrote:
> >>> When the device is connected to a host without a gadget driver,
> >>> otg->gadget is NULL.
> >>>
> >>> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> >>> ---
> >>>  drivers/usb/musb/musb_core.c | 3 ++-
> >>>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> >>> index 18e877f..baa4f6a 100644
> >>> --- a/drivers/usb/musb/musb_core.c
> >>> +++ b/drivers/usb/musb/musb_core.c
> >>> @@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
> >>>                               break;
> >>>               case OTG_STATE_B_PERIPHERAL:
> >>
> >> why would we be in B peripheral if we're host only ? Bug seems to be
> >> else where.
> >
> > We are not host, we are in device mode.
> >
> > But I would think the proper fix should be not setting
> > DEVCTL[SOFTCONN] until a gadget driver is loaded. Then the host will
> > not see the device which does not have a gadget driver.
> 
> Sorry, I meant POWER[SOFTCONN] bit.

I agree with you and my bad that I misread commit log.
diff mbox

Patch

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 18e877f..baa4f6a 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -654,7 +654,8 @@  static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
 				break;
 		case OTG_STATE_B_PERIPHERAL:
 			musb_g_suspend(musb);
-			musb->is_active = otg->gadget->b_hnp_enable;
+			musb->is_active = otg->gadget &&
+					otg->gadget->b_hnp_enable;
 			if (musb->is_active) {
 				musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
 				dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");