netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Heiner Kallweit <hkallweit1@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>, David Miller <davem@davemloft.net>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next] net: phy: avoid NPE if read_page/write_page callbacks are not available
Date: Wed, 16 Oct 2019 13:20:35 -0700	[thread overview]
Message-ID: <fd0cf2fb-22f4-44b6-8559-25bfe61609bd@gmail.com> (raw)
In-Reply-To: <41aba46c-6d75-9a15-9360-1336110dd28e@gmail.com>

On 10/16/19 12:53 PM, Heiner Kallweit wrote:
> Currently there's a bug in the module subsystem [0] preventing load of
> the PHY driver module on certain systems (as one symptom).
> This results in a NPE on such systems for the following reason:
> Instead of the correct PHY driver the genphy driver is loaded that
> doesn't implement the read_page/write_page callbacks. Every call to
> phy_read_paged() et al will result in a NPE therefore.
> 
> In parallel to fixing the root cause we should make sure that this one
> and maybe similar issues in other subsystems don't result in a NPE
> in phylib. So let's check for the callbacks before using them and warn
> once if they are not available.

Everywhere else in the PHY library we tend to do:

if (!phydev->drv)
	return -EIO;

maybe not the best choice for an error code, but we should be consistent.

Is the issue really that we do have a driver we are bound to, but
somehow we cannot resolve the read_page/write_page callbacks to a valid
function pointer?

> 
> [0] https://marc.info/?t=157072642100001&r=1&w=2
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/phy-core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
> index 9412669b5..0ae1722ba 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -689,11 +689,17 @@ EXPORT_SYMBOL_GPL(phy_modify_mmd);
>  
>  static int __phy_read_page(struct phy_device *phydev)
>  {
> +	if (WARN_ONCE(!phydev->drv->read_page, "read_page callback not available, PHY driver not loaded?\n"))
> +		return -EOPNOTSUPP;
> +
>  	return phydev->drv->read_page(phydev);
>  }
>  
>  static int __phy_write_page(struct phy_device *phydev, int page)
>  {
> +	if (WARN_ONCE(!phydev->drv->write_page, "write_page callback not available, PHY driver not loaded?\n"))
> +		return -EOPNOTSUPP;
> +
>  	return phydev->drv->write_page(phydev, page);
>  }
>  
> 


-- 
Florian

  reply	other threads:[~2019-10-16 20:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16 19:53 [PATCH net-next] net: phy: avoid NPE if read_page/write_page callbacks are not available Heiner Kallweit
2019-10-16 20:20 ` Florian Fainelli [this message]
2019-10-16 20:26   ` Heiner Kallweit
2019-10-18 16:58 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd0cf2fb-22f4-44b6-8559-25bfe61609bd@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).