Skip to contentSkip to conversation

pda_power: USB notifier fixes

PATCH In review Mathias Krause 2 participants 8 messages Mar 30, 2014 – Apr 14, 2014

lore
Share & tools
lore
#0 lore raw

cover pda_power: USB notifier fixes

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(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/2 pda_power: Statically initialize notifier block

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 <[email protected]>
Cc Felipe Balbi <[email protected]>
Cc Anton Vorontsov <[email protected]>
---
 drivers/power/pda_power.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/power/pda_power.c +4 -2
index 0c52e2a0d9..87a963d0a8 100644
@@ -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");
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/2 pda_power: Unregister USB notifier in pda_power_remove()

In reply to Mathias Krause

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 <[email protected]>
Cc Anton Vorontsov <[email protected]>
---
 drivers/power/pda_power.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/power/pda_power.c +5 -0
index 87a963d0a8..aba23d6848 100644
@@ -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);
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()

Quoted 16 lines · Mathias Krause

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 <[email protected]>
Cc Anton Vorontsov <[email protected]>
---
 drivers/power/pda_power.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/power/pda_power.c +0 -0
index 87a963d0a8..aba23d6848 100644

drivers/power/pda_power.c static int pda_power_remove(struct platform_device *pdev) · line 434

Quoted 5 lines
drivers/power/pda_power.c +2 -0
@@ -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.

Quoted 9 lines
drivers/power/pda_power.c +3 -0
+		usb_unregister_notifier(transceiver, &otg_nb);
+#endif
+
 	if (polling)
 		del_timer_sync(&polling_timer);
 	del_timer_sync(&charger_timer);
Signature · 1 line
1.7.10.4
Signature · 1 line
balbi
#4 lore raw

Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()

Quoted 20 lines · Felipe Balbi
Quoted 19 lines · Mathias Krause

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 <[email protected]>
Cc Anton Vorontsov <[email protected]>
---
 drivers/power/pda_power.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/power/pda_power.c +0 -0
index 87a963d0a8..aba23d6848 100644
@@ -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);
 
Quoted 4 lines

drivers/power/pda_power.c static int pda_power_remove(struct platform_device *pdev) · line 434

Quoted 2 lines
drivers/power/pda_power.c +2 -0
+#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.

Quoted 13 lines
Quoted 10 lines
drivers/power/pda_power.c +3 -1
+             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

#5 lore raw

Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()

Quoted 26 lines · Mathias Krause
Quoted 20 lines · Felipe Balbi
Quoted 19 lines · Mathias Krause

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 <[email protected]>
Cc Anton Vorontsov <[email protected]>
---
 drivers/power/pda_power.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/power/pda_power.c +0 -0
index 87a963d0a8..aba23d6848 100644
@@ -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);
 
Quoted 4 lines

drivers/power/pda_power.c static int pda_power_remove(struct platform_device *pdev) · line 434

Quoted 2 lines
drivers/power/pda_power.c +2 -0
+#if IS_ENABLED(CONFIG_USB_PHY)
+     if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier)

IS_ERR() should be enough here.

Quoted 5 lines

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 ?

Quoted 5 lines

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

Signature · 1 line
balbi
#6 lore raw

Re: [PATCH 2/2] pda_power: Unregister USB notifier in pda_power_remove()

Quoted 27 lines · Felipe Balbi
Quoted 26 lines · Mathias Krause
Quoted 24 lines · Felipe Balbi
Quoted 16 lines · Mathias Krause

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 <[email protected]>
Cc Anton Vorontsov <[email protected]>
---
 drivers/power/pda_power.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/power/pda_power.c +0 -0
index 87a963d0a8..aba23d6848 100644

drivers/power/pda_power.c static int pda_power_remove(struct platform_device *pdev) · line 434

Quoted 5 lines
drivers/power/pda_power.c +2 -0
@@ -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.

Quoted 7 lines
Quoted 5 lines

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.

Quoted 11 lines
Quoted 6 lines

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

#7 lore raw
In reply to Mathias Krause
Quoted 10 lines · Mathias Krause

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!

Quoted 8 lines

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?