netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: fec: normalize return value of pm_runtime_get_sync() in MDIO write
@ 2015-09-03 19:38 Maciej S. Szmigiero
  2015-09-03 19:49 ` Andrew Lunn
  2015-09-06  5:04 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Maciej S. Szmigiero @ 2015-09-03 19:38 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Nimrod Andy, Frank Li,
	"Lothar Waßmann",
	Fabio Estevam, Andrew Lunn, linux-kernel

If fec MDIO write method succeeds its return value comes from
call to pm_runtime_get_sync().
But pm_runtime_get_sync() can also return 1.

In case of Micrel KSZ9031 PHY this value will then
be returned along the call chain of phy_write() ->
ksz9031_extended_write() -> ksz9031_center_flp_timing() ->
ksz9031_config_init() -> phy_init_hw() -> phy_attach_direct() ->
phy_connect_direct().

Then phy_connect() will cast it into a pointer using ERR_PTR(),
which then fec_enet_mii_probe() will try to dereference
resulting in an oops.

Fix it by normalizing return value of pm_runtime_get_sync()
to be zero if positive in MDIO write method.

Signed-off-by: Maciej Szmigiero <mail@maciej.szmigiero.name>
---
 drivers/net/ethernet/freescale/fec_main.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 91925e3..6cc3340 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1816,11 +1816,13 @@ static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum,
 	struct fec_enet_private *fep = bus->priv;
 	struct device *dev = &fep->pdev->dev;
 	unsigned long time_left;
-	int ret = 0;
+	int ret;
 
 	ret = pm_runtime_get_sync(dev);
 	if (ret < 0)
 		return ret;
+	else
+		ret = 0;
 
 	fep->mii_timeout = 0;
 	reinit_completion(&fep->mdio_done);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: fec: normalize return value of pm_runtime_get_sync() in MDIO write
  2015-09-03 19:38 [PATCH] net: fec: normalize return value of pm_runtime_get_sync() in MDIO write Maciej S. Szmigiero
@ 2015-09-03 19:49 ` Andrew Lunn
  2015-09-06  5:04 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2015-09-03 19:49 UTC (permalink / raw)
  To: Maciej S. Szmigiero
  Cc: netdev, David S. Miller, Nimrod Andy, Frank Li,
	"Lothar Waßmann",
	Fabio Estevam, linux-kernel

On Thu, Sep 03, 2015 at 09:38:30PM +0200, Maciej S. Szmigiero wrote:
> If fec MDIO write method succeeds its return value comes from
> call to pm_runtime_get_sync().
> But pm_runtime_get_sync() can also return 1.
> 
> In case of Micrel KSZ9031 PHY this value will then
> be returned along the call chain of phy_write() ->
> ksz9031_extended_write() -> ksz9031_center_flp_timing() ->
> ksz9031_config_init() -> phy_init_hw() -> phy_attach_direct() ->
> phy_connect_direct().
> 
> Then phy_connect() will cast it into a pointer using ERR_PTR(),
> which then fec_enet_mii_probe() will try to dereference
> resulting in an oops.
> 
> Fix it by normalizing return value of pm_runtime_get_sync()
> to be zero if positive in MDIO write method.
> 
> Signed-off-by: Maciej Szmigiero <mail@maciej.szmigiero.name>

Fixes: 8fff755e9f8d ("net: fec: Ensure clocks are enabled while using mdio bus")

Acked-by: Andrew Lunn <andrew@lunn.ch>

Thanks
	Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: fec: normalize return value of pm_runtime_get_sync() in MDIO write
  2015-09-03 19:38 [PATCH] net: fec: normalize return value of pm_runtime_get_sync() in MDIO write Maciej S. Szmigiero
  2015-09-03 19:49 ` Andrew Lunn
@ 2015-09-06  5:04 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-09-06  5:04 UTC (permalink / raw)
  To: mail; +Cc: netdev, B38611, Frank.Li, LW, fabio.estevam, andrew, linux-kernel

From: "Maciej S. Szmigiero" <mail@maciej.szmigiero.name>
Date: Thu, 03 Sep 2015 21:38:30 +0200

> If fec MDIO write method succeeds its return value comes from
> call to pm_runtime_get_sync().
> But pm_runtime_get_sync() can also return 1.
> 
> In case of Micrel KSZ9031 PHY this value will then
> be returned along the call chain of phy_write() ->
> ksz9031_extended_write() -> ksz9031_center_flp_timing() ->
> ksz9031_config_init() -> phy_init_hw() -> phy_attach_direct() ->
> phy_connect_direct().
> 
> Then phy_connect() will cast it into a pointer using ERR_PTR(),
> which then fec_enet_mii_probe() will try to dereference
> resulting in an oops.
> 
> Fix it by normalizing return value of pm_runtime_get_sync()
> to be zero if positive in MDIO write method.
> 
> Signed-off-by: Maciej Szmigiero <mail@maciej.szmigiero.name>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-06  5:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 19:38 [PATCH] net: fec: normalize return value of pm_runtime_get_sync() in MDIO write Maciej S. Szmigiero
2015-09-03 19:49 ` Andrew Lunn
2015-09-06  5:04 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).