[2/2] pda_power: Unregister USB notifier in pda_power_remove()
diff mbox series

Message ID 1396186455-3276-3-git-send-email-minipli@googlemail.com
State New, archived
Headers show
Series
  • pda_power: USB notifier fixes
Related show

Commit Message

Mathias Krause March 30, 2014, 1:34 p.m. UTC
If we've registered a notifier in pda_power_probe() we must deregister
it in pda_power_remove() to not let it work on stale data like, e.g.,
the charger timer.

Cc: Felipe Balbi <balbi@ti.com>
Cc: Anton Vorontsov <anton@enomsg.org>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 drivers/power/pda_power.c |    5 +++++
 1 file changed, 5 insertions(+)

Comments

Felipe Balbi April 14, 2014, 9:35 p.m. UTC | #1
On Sun, Mar 30, 2014 at 03:34:15PM +0200, Mathias Krause wrote:
> If we've registered a notifier in pda_power_probe() we must deregister
> it in pda_power_remove() to not let it work on stale data like, e.g.,
> the charger timer.
> 
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Anton Vorontsov <anton@enomsg.org>
> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> ---
>  drivers/power/pda_power.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
> index 87a963d0a8..aba23d6848 100644
> --- a/drivers/power/pda_power.c
> +++ b/drivers/power/pda_power.c
> @@ -430,6 +430,11 @@ static int pda_power_remove(struct platform_device *pdev)
>  	if (pdata->is_ac_online && ac_irq)
>  		free_irq(ac_irq->start, &pda_psy_ac);
>  
> +#if IS_ENABLED(CONFIG_USB_PHY)
> +	if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier)

IS_ERR() should be enough here.

> +		usb_unregister_notifier(transceiver, &otg_nb);
> +#endif
> +
>  	if (polling)
>  		del_timer_sync(&polling_timer);
>  	del_timer_sync(&charger_timer);
> -- 
> 1.7.10.4
>
Mathias Krause April 14, 2014, 10:07 p.m. UTC | #2
On 14 April 2014 23:35, Felipe Balbi <balbi@ti.com> wrote:
> On Sun, Mar 30, 2014 at 03:34:15PM +0200, Mathias Krause wrote:
>> If we've registered a notifier in pda_power_probe() we must deregister
>> it in pda_power_remove() to not let it work on stale data like, e.g.,
>> the charger timer.
>>
>> Cc: Felipe Balbi <balbi@ti.com>
>> Cc: Anton Vorontsov <anton@enomsg.org>
>> Signed-off-by: Mathias Krause <minipli@googlemail.com>
>> ---
>>  drivers/power/pda_power.c |    5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
>> index 87a963d0a8..aba23d6848 100644
>> --- a/drivers/power/pda_power.c
>> +++ b/drivers/power/pda_power.c
>> @@ -430,6 +430,11 @@ static int pda_power_remove(struct platform_device *pdev)
>>       if (pdata->is_ac_online && ac_irq)
>>               free_irq(ac_irq->start, &pda_psy_ac);
>>
>> +#if IS_ENABLED(CONFIG_USB_PHY)
>> +     if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier)
>
> IS_ERR() should be enough here.

That's true! The usb_get_phy() call in pda_power_probe() will always
return a valid pointer or an ERR_PTR() -- never NULL. Albeit, looking
at usb_get_phy(), it contains another bug, returning a valid pointer,
even when the try_module_get() call fails. *sigh* It should set ptr to
an ERR_PTR() in this case.

Anyway, probably all the transceiver checks in pda_power.c can be
changed to IS_ERR() checks. The reason I am using IS_ERR_OR_NULL() in
my patch is that I just copied the test from a few lines below. I'll
create a follow up patch in case somebody cares about this series in
the first place.

>
>> +             usb_unregister_notifier(transceiver, &otg_nb);
>> +#endif
>> +
>>       if (polling)
>>               del_timer_sync(&polling_timer);
>>       del_timer_sync(&charger_timer);
>> --
>> 1.7.10.4
>>
>
> --
> balbi

Thanks,
Mathias
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Felipe Balbi April 14, 2014, 10:08 p.m. UTC | #3
On Tue, Apr 15, 2014 at 12:07:13AM +0200, Mathias Krause wrote:
> On 14 April 2014 23:35, Felipe Balbi <balbi@ti.com> wrote:
> > On Sun, Mar 30, 2014 at 03:34:15PM +0200, Mathias Krause wrote:
> >> If we've registered a notifier in pda_power_probe() we must deregister
> >> it in pda_power_remove() to not let it work on stale data like, e.g.,
> >> the charger timer.
> >>
> >> Cc: Felipe Balbi <balbi@ti.com>
> >> Cc: Anton Vorontsov <anton@enomsg.org>
> >> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> >> ---
> >>  drivers/power/pda_power.c |    5 +++++
> >>  1 file changed, 5 insertions(+)
> >>
> >> diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
> >> index 87a963d0a8..aba23d6848 100644
> >> --- a/drivers/power/pda_power.c
> >> +++ b/drivers/power/pda_power.c
> >> @@ -430,6 +430,11 @@ static int pda_power_remove(struct platform_device *pdev)
> >>       if (pdata->is_ac_online && ac_irq)
> >>               free_irq(ac_irq->start, &pda_psy_ac);
> >>
> >> +#if IS_ENABLED(CONFIG_USB_PHY)
> >> +     if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier)
> >
> > IS_ERR() should be enough here.
> 
> That's true! The usb_get_phy() call in pda_power_probe() will always
> return a valid pointer or an ERR_PTR() -- never NULL. Albeit, looking
> at usb_get_phy(), it contains another bug, returning a valid pointer,
> even when the try_module_get() call fails. *sigh* It should set ptr to
> an ERR_PTR() in this case.

good catch, can you send a patch for that ?

> Anyway, probably all the transceiver checks in pda_power.c can be
> changed to IS_ERR() checks. The reason I am using IS_ERR_OR_NULL() in
> my patch is that I just copied the test from a few lines below. I'll
> create a follow up patch in case somebody cares about this series in
> the first place.

awesome, thanks
Mathias Krause April 14, 2014, 10:11 p.m. UTC | #4
On 15 April 2014 00:08, Felipe Balbi <balbi@ti.com> wrote:
> On Tue, Apr 15, 2014 at 12:07:13AM +0200, Mathias Krause wrote:
>> On 14 April 2014 23:35, Felipe Balbi <balbi@ti.com> wrote:
>> > On Sun, Mar 30, 2014 at 03:34:15PM +0200, Mathias Krause wrote:
>> >> If we've registered a notifier in pda_power_probe() we must deregister
>> >> it in pda_power_remove() to not let it work on stale data like, e.g.,
>> >> the charger timer.
>> >>
>> >> Cc: Felipe Balbi <balbi@ti.com>
>> >> Cc: Anton Vorontsov <anton@enomsg.org>
>> >> Signed-off-by: Mathias Krause <minipli@googlemail.com>
>> >> ---
>> >>  drivers/power/pda_power.c |    5 +++++
>> >>  1 file changed, 5 insertions(+)
>> >>
>> >> diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
>> >> index 87a963d0a8..aba23d6848 100644
>> >> --- a/drivers/power/pda_power.c
>> >> +++ b/drivers/power/pda_power.c
>> >> @@ -430,6 +430,11 @@ static int pda_power_remove(struct platform_device *pdev)
>> >>       if (pdata->is_ac_online && ac_irq)
>> >>               free_irq(ac_irq->start, &pda_psy_ac);
>> >>
>> >> +#if IS_ENABLED(CONFIG_USB_PHY)
>> >> +     if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier)
>> >
>> > IS_ERR() should be enough here.
>>
>> That's true! The usb_get_phy() call in pda_power_probe() will always
>> return a valid pointer or an ERR_PTR() -- never NULL. Albeit, looking
>> at usb_get_phy(), it contains another bug, returning a valid pointer,
>> even when the try_module_get() call fails. *sigh* It should set ptr to
>> an ERR_PTR() in this case.
>
> good catch, can you send a patch for that ?

Sure, will do it tomorrow.

>
>> Anyway, probably all the transceiver checks in pda_power.c can be
>> changed to IS_ERR() checks. The reason I am using IS_ERR_OR_NULL() in
>> my patch is that I just copied the test from a few lines below. I'll
>> create a follow up patch in case somebody cares about this series in
>> the first place.
>
> awesome, thanks
>
> --
> balbi


Cheers,
Mathias
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 87a963d0a8..aba23d6848 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -430,6 +430,11 @@  static int pda_power_remove(struct platform_device *pdev)
 	if (pdata->is_ac_online && ac_irq)
 		free_irq(ac_irq->start, &pda_psy_ac);
 
+#if IS_ENABLED(CONFIG_USB_PHY)
+	if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier)
+		usb_unregister_notifier(transceiver, &otg_nb);
+#endif
+
 	if (polling)
 		del_timer_sync(&polling_timer);
 	del_timer_sync(&charger_timer);