* [PATCH 0/2] pda_power: USB notifier fixes
@ 2014-03-30 13:34 Mathias Krause
2014-03-30 13:34 ` [PATCH 1/2] pda_power: Statically initialize notifier block Mathias Krause
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Mathias Krause @ 2014-03-30 13:34 UTC (permalink / raw)
To: Dmitry Eremin-Solenikov, David Woodhouse
Cc: linux-kernel, Mathias Krause, PaX Team, Felipe Balbi, Anton Vorontsov
The notifier block can and should be initialized statically. Fixed in
patch 1.
While doing patch 1 I noticed, that the USB notifier that gets registered
in pda_power_probe() never gets unregistered. Fixed in patch 2.
Beware: The patches are compile tested only, as I have no such hardware!
Please apply!
Mathias Krause (2):
pda_power: Statically initialize notifier block
pda_power: Unregister USB notifier in pda_power_remove()
drivers/power/pda_power.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] pda_power: Statically initialize notifier block
2014-03-30 13:34 [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
@ 2014-03-30 13:34 ` Mathias Krause
2014-03-30 13:34 ` [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove() Mathias Krause
2014-04-14 19:51 ` [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
2 siblings, 0 replies; 8+ messages in thread
From: Mathias Krause @ 2014-03-30 13:34 UTC (permalink / raw)
To: Dmitry Eremin-Solenikov, David Woodhouse
Cc: linux-kernel, Mathias Krause, PaX Team, Felipe Balbi, Anton Vorontsov
Instead of initializing the notifier block in pda_power_probe(),
initialize it statically. This safes us some code.
Found in the PaX patch, written by the PaX Team.
Cc: PaX Team <pageexec@freemail.hu>
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 | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 0c52e2a0d9..87a963d0a8 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -37,7 +37,6 @@ static int polling;
#if IS_ENABLED(CONFIG_USB_PHY)
static struct usb_phy *transceiver;
-static struct notifier_block otg_nb;
#endif
static struct regulator *ac_draw;
@@ -258,6 +257,10 @@ static int otg_handle_notification(struct notifier_block *nb,
return NOTIFY_OK;
}
+
+static struct notifier_block otg_nb = {
+ .notifier_call = otg_handle_notification,
+};
#endif
static int pda_power_probe(struct platform_device *pdev)
@@ -369,7 +372,6 @@ static int pda_power_probe(struct platform_device *pdev)
#if IS_ENABLED(CONFIG_USB_PHY)
if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
- otg_nb.notifier_call = otg_handle_notification;
ret = usb_register_notifier(transceiver, &otg_nb);
if (ret) {
dev_err(dev, "failure to register otg notifier\n");
--
1.7.10.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()
2014-03-30 13:34 [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
2014-03-30 13:34 ` [PATCH 1/2] pda_power: Statically initialize notifier block Mathias Krause
@ 2014-03-30 13:34 ` Mathias Krause
2014-04-14 21:35 ` Felipe Balbi
2014-04-14 19:51 ` [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
2 siblings, 1 reply; 8+ messages in thread
From: Mathias Krause @ 2014-03-30 13:34 UTC (permalink / raw)
To: Dmitry Eremin-Solenikov, David Woodhouse
Cc: linux-kernel, Mathias Krause, PaX Team, Felipe Balbi, Anton Vorontsov
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)
+ usb_unregister_notifier(transceiver, &otg_nb);
+#endif
+
if (polling)
del_timer_sync(&polling_timer);
del_timer_sync(&charger_timer);
--
1.7.10.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] pda_power: USB notifier fixes
2014-03-30 13:34 [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
2014-03-30 13:34 ` [PATCH 1/2] pda_power: Statically initialize notifier block Mathias Krause
2014-03-30 13:34 ` [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove() Mathias Krause
@ 2014-04-14 19:51 ` Mathias Krause
2 siblings, 0 replies; 8+ messages in thread
From: Mathias Krause @ 2014-04-14 19:51 UTC (permalink / raw)
To: Dmitry Eremin-Solenikov, David Woodhouse
Cc: linux-kernel, Mathias Krause, PaX Team, Felipe Balbi, Anton Vorontsov
On 30 March 2014 15:34, Mathias Krause <minipli@googlemail.com> wrote:
> The notifier block can and should be initialized statically. Fixed in
> patch 1.
>
> While doing patch 1 I noticed, that the USB notifier that gets registered
> in pda_power_probe() never gets unregistered. Fixed in patch 2.
>
> Beware: The patches are compile tested only, as I have no such hardware!
>
> Please apply!
>
> Mathias Krause (2):
> pda_power: Statically initialize notifier block
> pda_power: Unregister USB notifier in pda_power_remove()
>
> drivers/power/pda_power.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> --
Ping? Any opinions on this series? Dmitry, David?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()
2014-03-30 13:34 ` [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove() Mathias Krause
@ 2014-04-14 21:35 ` Felipe Balbi
2014-04-14 22:07 ` Mathias Krause
0 siblings, 1 reply; 8+ messages in thread
From: Felipe Balbi @ 2014-04-14 21:35 UTC (permalink / raw)
To: Mathias Krause
Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, PaX Team,
Felipe Balbi, Anton Vorontsov
[-- Attachment #1: Type: text/plain, Size: 1150 bytes --]
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
>
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()
2014-04-14 21:35 ` Felipe Balbi
@ 2014-04-14 22:07 ` Mathias Krause
2014-04-14 22:08 ` Felipe Balbi
0 siblings, 1 reply; 8+ messages in thread
From: Mathias Krause @ 2014-04-14 22:07 UTC (permalink / raw)
To: Felipe Balbi
Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, PaX Team,
Anton Vorontsov
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()
2014-04-14 22:07 ` Mathias Krause
@ 2014-04-14 22:08 ` Felipe Balbi
2014-04-14 22:11 ` Mathias Krause
0 siblings, 1 reply; 8+ messages in thread
From: Felipe Balbi @ 2014-04-14 22:08 UTC (permalink / raw)
To: Mathias Krause
Cc: Felipe Balbi, Dmitry Eremin-Solenikov, David Woodhouse,
linux-kernel, PaX Team, Anton Vorontsov
[-- Attachment #1: Type: text/plain, Size: 1879 bytes --]
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
--
balbi
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()
2014-04-14 22:08 ` Felipe Balbi
@ 2014-04-14 22:11 ` Mathias Krause
0 siblings, 0 replies; 8+ messages in thread
From: Mathias Krause @ 2014-04-14 22:11 UTC (permalink / raw)
To: Felipe Balbi
Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-kernel, PaX Team,
Anton Vorontsov
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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-04-14 22:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-30 13:34 [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
2014-03-30 13:34 ` [PATCH 1/2] pda_power: Statically initialize notifier block Mathias Krause
2014-03-30 13:34 ` [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove() Mathias Krause
2014-04-14 21:35 ` Felipe Balbi
2014-04-14 22:07 ` Mathias Krause
2014-04-14 22:08 ` Felipe Balbi
2014-04-14 22:11 ` Mathias Krause
2014-04-14 19:51 ` [PATCH 0/2] pda_power: USB notifier fixes Mathias Krause
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®