otg-for-v3.9-v1: USB otg: fix usage of try_module_get() and module_put()
Subsystems (3)
PATCH 1/1 otg-for-v3.9-v1: USB otg: fix usage of try_module_get() and module_put()
Hello,
this patch is intended for v3.9 and applies to Greg's usb/master tree. If fixes the use of try_module_get() and module_put() in all usb_get_phy functions.
regards,
Marc
The following changes since commit 74e1a2a39355b2d3ae8c60c78d8add162c6d7183:
Merge tag 'usb-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb (2013-02-21 12:20:00 -0800)
are available in the git repository at:
git://git.pengutronix.de/git/mkl/linux.git tags/otg-for-v3.9-v1
for you to fetch changes up to 6bef020b4aebd7886281fb7fb37c788d5a365eea:
USB otg: use try_module_get in all usb_get_phy functions and add missing module_put (2013-02-27 12:53:15 +0100)
----------------------------------------------------------------
USB otg: add missing try_module_get and module_put
Add try_module_get() to usb_get_phy() and usb_get_phy_dev(). Further the missing module_put() is added to usb_put_phy()
----------------------------------------------------------------
Marc Kleine-Budde (1):
USB otg: use try_module_get in all usb_get_phy functions and add missing module_put
drivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
PATCH 1/1 USB otg: use try_module_get in all usb_get_phy functions and add missing module_put
In patch "5d3c28b usb: otg: add device tree support to otg library" devm_usb_get_phy_by_phandle() was added. It uses try_module_get() to lock the phy driver in memory. The corresponding module_put() is missing in that patch.
This patch adds try_module_get() to usb_get_phy() and usb_get_phy_dev(). Further the missing module_put() is added to usb_put_phy().
--- drivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/otg/otg.c +7 -3
@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)spin_lock_irqsave (&phy_lock, flags); phy =__usb_find_phy (&phy_list, type); -if (IS_ERR (phy)) { +if (IS_ERR (phy) || !try_module_get (phy->dev->driver->owner)) {pr_err ("unable to find transceiver of type %s\n" ,usb_phy_type_string (type)); goto err0;
@@ -228,7 +228,7 @@ struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)spin_lock_irqsave (&phy_lock, flags); phy =__usb_find_phy_dev (dev, &phy_bind_list, index); -if (IS_ERR (phy)) { +if (IS_ERR (phy) || !try_module_get (phy->dev->driver->owner)) {pr_err ("unable to find transceiver\n" ); goto err0; }
@@ -301,8 +301,12 @@ EXPORT_SYMBOL(devm_usb_put_phy);*/ void usb_put_phy (struct usb_phy *x) { -if (x) +if (x) { +struct module *owner = x->dev->driver->owner; +put_device (x->dev); +module_put (owner); + } }EXPORT_SYMBOL (usb_put_phy);
Signature · 1 line
1.7.10.4
Greg KH
maintainerPATCH 1/1 USB otg: use try_module_get in all usb_get_phy functions and add missing module_put
Quoted 20 lines · Marc Kleine-Budde
In patch "5d3c28b usb: otg: add device tree support to otg library"
devm_usb_get_phy_by_phandle()was added. It usestry_module_get()to lock the phy driver in memory. The correspondingmodule_put()is missing in that patch.This patch adds
try_module_get()tousb_get_phy()andusb_get_phy_dev(). Further the missingmodule_put()is added tousb_put_phy().Reviewed-by Kishon Vijay Abraham I <[email protected]>Acked-by Felipe Balbi <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>Signed-off-by Michael Grzeschik <[email protected]>--- drivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/usb/otg/otg.c +0
-0
drivers/usb/otg/otg.c struct usb_phy *usb_get_phy(enum usb_phy_type type) · line 133
Quoted 5 lines
drivers/usb/otg/otg.c +1
-1@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)spin_lock_irqsave (&phy_lock, flags); phy =__usb_find_phy (&phy_list, type); -if (IS_ERR (phy)) { +if (IS_ERR (phy) || !try_module_get (phy->dev->driver->owner)) {
Ugh, really? We really are trying this type of module locking mess?
Why? What is it solving? What's wrong with having the module be able to be unloaded whenever it wants to? No one should be doing that and expecting that their hardware would still work properly, right?
I really don't like this type of thing, sorry.
greg k-h
PATCH 1/1 USB otg: use try_module_get in all usb_get_phy functions and add missing module_put
Quoted 23 lines · Greg KH
Quoted 22 lines · Marc Kleine-Budde
In patch "5d3c28b usb: otg: add device tree support to otg library"
devm_usb_get_phy_by_phandle()was added. It usestry_module_get()to lock the phy driver in memory. The correspondingmodule_put()is missing in that patch.This patch adds
try_module_get()tousb_get_phy()andusb_get_phy_dev(). Further the missingmodule_put()is added tousb_put_phy().Reviewed-by Kishon Vijay Abraham I <[email protected]>Acked-by Felipe Balbi <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>Signed-off-by Michael Grzeschik <[email protected]>--- drivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/usb/otg/otg.c +0
-0@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)spin_lock_irqsave (&phy_lock, flags);
Quoted 7 lines
drivers/usb/otg/otg.c struct usb_phy *usb_get_phy(enum usb_phy_type type) · line 133
Quoted 3 lines
drivers/usb/otg/otg.c +1
-1phy =__usb_find_phy (&phy_list, type); -if (IS_ERR (phy)) { +if (IS_ERR (phy) || !try_module_get (phy->dev->driver->owner)) {Ugh, really? We really are trying this type of module locking mess?
Why? What is it solving? What's wrong with having the module be able
Without this patch, you can unload the phy module, while it is in use. As the phy framework doesn't use any existing abstraction to handle phy <-> user of phy pairing/unpairing (it's all open coded), any subsequent use of the phy's callback will result in deref'ing bogus pointers.
Quoted 2 lines
to be unloaded whenever it wants to? No one should be doing that and expecting that their hardware would still work properly, right?
Yes, but it should not result in an kernel oops.
Quoted 1 line
I really don't like this type of thing, sorry.
Can you point Kishon and me to a better implementation?
Marc
Signature · 12 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de | -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 263 bytes Desc: OpenPGP digital signature URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130227/6b5ac10f/attachment.sig>
Greg KH
maintainerPATCH 1/1 USB otg: use try_module_get in all usb_get_phy functions and add missing module_put
Quoted 30 lines · Marc Kleine-Budde
Quoted 29 lines · Greg KH
Quoted 20 lines · Marc Kleine-Budde
In patch "5d3c28b usb: otg: add device tree support to otg library"
devm_usb_get_phy_by_phandle()was added. It usestry_module_get()to lock the phy driver in memory. The correspondingmodule_put()is missing in that patch.This patch adds
try_module_get()tousb_get_phy()andusb_get_phy_dev(). Further the missingmodule_put()is added tousb_put_phy().Reviewed-by Kishon Vijay Abraham I <[email protected]>Acked-by Felipe Balbi <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>Signed-off-by Michael Grzeschik <[email protected]>--- drivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/usb/otg/otg.c +0
-0drivers/usb/otg/otg.c struct usb_phy *usb_get_phy(enum usb_phy_type type) · line 133
Quoted 5 lines
drivers/usb/otg/otg.c +1
-1@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)spin_lock_irqsave (&phy_lock, flags); phy =__usb_find_phy (&phy_list, type); -if (IS_ERR (phy)) { +if (IS_ERR (phy) || !try_module_get (phy->dev->driver->owner)) {Ugh, really? We really are trying this type of module locking mess?
Quoted 6 lines
Quoted 1 line
Why? What is it solving? What's wrong with having the module be able
Without this patch, you can unload the phy module, while it is in use. As the phy framework doesn't use any existing abstraction to handle phy <-> user of phy pairing/unpairing (it's all open coded), any subsequent use of the phy's callback will result in deref'ing bogus pointers.
Then perhaps we should fix the open-coded-ness of the phy layer?
Quoted 4 lines
Quoted 2 lines
to be unloaded whenever it wants to? No one should be doing that and expecting that their hardware would still work properly, right?
Yes, but it should not result in an kernel oops.
Agreed.
Quoted 3 lines
Quoted 1 line
I really don't like this type of thing, sorry.
Can you point Kishon and me to a better implementation?
Wasn't someone working on a "generic" phy layer for the kernel? That should probably resolve this issue there.
But in looking at this further, you are right, this is about the only way this can be solved now. It is a pretty minor problem though.
I'll wait for this to come in from Felipe into my trees.
thanks,
greg k-h
PATCH 1/1 USB otg: use try_module_get in all usb_get_phy functions and add missing module_put
Hi,
Quoted 45 lines · Greg KH
Quoted 30 lines · Marc Kleine-Budde
Quoted 29 lines · Greg KH
Quoted 20 lines · Marc Kleine-Budde
In patch "5d3c28b usb: otg: add device tree support to otg library"
devm_usb_get_phy_by_phandle()was added. It usestry_module_get()to lock the phy driver in memory. The correspondingmodule_put()is missing in that patch.This patch adds
try_module_get()tousb_get_phy()andusb_get_phy_dev(). Further the missingmodule_put()is added tousb_put_phy().Reviewed-by Kishon Vijay Abraham I <[email protected]>Acked-by Felipe Balbi <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>Signed-off-by Michael Grzeschik <[email protected]>--- drivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/usb/otg/otg.c +0
-0drivers/usb/otg/otg.c struct usb_phy *usb_get_phy(enum usb_phy_type type) · line 133
Quoted 5 lines
drivers/usb/otg/otg.c +1
-1@@ -130,7 +130,7 @@ struct usb_phy *usb_get_phy(enum usb_phy_type type)spin_lock_irqsave (&phy_lock, flags); phy =__usb_find_phy (&phy_list, type); -if (IS_ERR (phy)) { +if (IS_ERR (phy) || !try_module_get (phy->dev->driver->owner)) {Ugh, really? We really are trying this type of module locking mess?
Quoted 6 lines
Quoted 1 line
Why? What is it solving? What's wrong with having the module be able
Without this patch, you can unload the phy module, while it is in use. As the phy framework doesn't use any existing abstraction to handle phy <-> user of phy pairing/unpairing (it's all open coded), any subsequent use of the phy's callback will result in deref'ing bogus pointers.
Then perhaps we should fix the open-coded-ness of the phy layer?
Quoted 4 lines
Quoted 2 lines
to be unloaded whenever it wants to? No one should be doing that and expecting that their hardware would still work properly, right?
Yes, but it should not result in an kernel oops.
Quoted 8 lines
Agreed.
Quoted 3 lines
Quoted 1 line
I really don't like this type of thing, sorry.
Can you point Kishon and me to a better implementation?
Wasn't someone working on a "generic" phy layer for the kernel? That should probably resolve this issue there.
Even in the generic PHY layer, we use *try_module_get* to avoid dereferencing bogus pointers.
Thanks
Kishon
PATCH 1/1 otg-for-v3.9-v1: USB otg: fix usage of try_module_get() and module_put()
In reply to Marc Kleine-BuddeQuoted 28 lines · Marc Kleine-Budde
Hello,
this patch is intended for v3.9 and applies to Greg's usb/master tree. If fixes the use of
try_module_get()andmodule_put()in allusb_get_phyfunctions.regards,
MarcThe following changes since commit
74e1a2a39355b2d3ae8c60c78d8add162c6d7183:Merge tag 'usb-3.9-rc1' of
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb(2013-02-21 12:20:00 -0800)are available in the git repository at:
git://git.pengutronix.de/git/mkl/linux.gittags/otg-for-v3.9-v1for you to fetch changes up to
6bef020b4aebd7886281fb7fb37c788d5a365eea:USB otg: use
try_module_getin allusb_get_phyfunctions and add missingmodule_put(2013-02-27 12:53:15 +0100)----------------------------------------------------------------
USB otg: add missingtry_module_getandmodule_putAdd
try_module_get()tousb_get_phy()andusb_get_phy_dev(). Further the missingmodule_put()is added tousb_put_phy()
Quoted 10 lines
----------------------------------------------------------------
Marc Kleine-Budde (1):
USB otg: usetry_module_getin allusb_get_phyfunctions and add missingmodule_putdrivers/usb/otg/otg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Hi,
with this series plus
otg-for-v3.10-v1: separate phy code and add DT helper
chipidea-for-v3.10-v1 : USB chipidea: make use of DT helpers in chipidea driver improve driver
v9: Add tested id switch and vbus connect detect support for Chipidea
and
arch/arm/boot/dts/imx28.dtsi +4 -2
@@ -907,7 +907,8 @@ compatible = "fsl,imx28-usb", "fsl,imx27-usb"; reg = <0x80080000 0x10000>; interrupts = <93>; - clocks = <&clks 60>; + clocks = <&clks 60>, <&clks 60>, <&clks 60>; + clock-names = "ipg", "ahb", "per"; fsl,usbphy = <&usbphy0>; status = "disabled"; };
@@ -916,7 +917,8 @@ compatible = "fsl,imx28-usb", "fsl,imx27-usb"; reg = <0x80090000 0x10000>; interrupts = <92>; - clocks = <&clks 61>; + clocks = <&clks 61>, <&clks 61>, <&clks 61>; + clock-names = "ipg", "ahb", "per"; fsl,usbphy = <&usbphy1>; status = "disabled"; };
I have USB otg+host working on v3.8 on an i.MX28.
So,
Regards,
Steffen
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |