netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver
@ 2020-01-16 17:46 Vladimir Oltean
  2020-01-16 17:48 ` Vladimir Oltean
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vladimir Oltean @ 2020-01-16 17:46 UTC (permalink / raw)
  To: davem, linux, andrew, f.fainelli, hkallweit1; +Cc: netdev, Alex Marginean

From: Alex Marginean <alexandru.marginean@nxp.com>

The APIs can be used by Ethernet drivers without actually loading a PHY
driver. This may become more widespread in the future with 802.3z
compatible MAC PCS devices being locally driven by the MAC driver when
configuring for a PHY mode with in-band negotiation.

Check that drv is not NULL before reading from it.

Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
---
If this hasn't been reported by now I assume it wasn't an issue so far.
So I've targeted the patch for net-next and not provided a Fixes: tag.

 drivers/net/phy/phy-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 769a076514b0..a4d2d59fceca 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -387,7 +387,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
 	if (regnum > (u16)~0 || devad > 32)
 		return -EINVAL;
 
-	if (phydev->drv->read_mmd) {
+	if (phydev->drv && phydev->drv->read_mmd) {
 		val = phydev->drv->read_mmd(phydev, devad, regnum);
 	} else if (phydev->is_c45) {
 		u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
@@ -444,7 +444,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
 	if (regnum > (u16)~0 || devad > 32)
 		return -EINVAL;
 
-	if (phydev->drv->write_mmd) {
+	if (phydev->drv && phydev->drv->write_mmd) {
 		ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
 	} else if (phydev->is_c45) {
 		u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
-- 
2.17.1


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

* Re: [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver
  2020-01-16 17:46 [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver Vladimir Oltean
@ 2020-01-16 17:48 ` Vladimir Oltean
  2020-01-16 17:52   ` Florian Fainelli
  2020-01-16 20:47 ` Heiner Kallweit
  2020-01-20  9:08 ` David Miller
  2 siblings, 1 reply; 6+ messages in thread
From: Vladimir Oltean @ 2020-01-16 17:48 UTC (permalink / raw)
  To: David S. Miller, Russell King - ARM Linux admin, Andrew Lunn,
	Florian Fainelli, Heiner Kallweit
  Cc: netdev, Alex Marginean

On Thu, 16 Jan 2020 at 19:46, Vladimir Oltean <olteanv@gmail.com> wrote:
>
> From: Alex Marginean <alexandru.marginean@nxp.com>
>
> The APIs can be used by Ethernet drivers without actually loading a PHY
> driver. This may become more widespread in the future with 802.3z
> compatible MAC PCS devices being locally driven by the MAC driver when
> configuring for a PHY mode with in-band negotiation.
>
> Check that drv is not NULL before reading from it.
>
> Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
> ---

Ugh. Can I just add here:

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

without resending?

> If this hasn't been reported by now I assume it wasn't an issue so far.
> So I've targeted the patch for net-next and not provided a Fixes: tag.
>
>  drivers/net/phy/phy-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
> index 769a076514b0..a4d2d59fceca 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -387,7 +387,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
>         if (regnum > (u16)~0 || devad > 32)
>                 return -EINVAL;
>
> -       if (phydev->drv->read_mmd) {
> +       if (phydev->drv && phydev->drv->read_mmd) {
>                 val = phydev->drv->read_mmd(phydev, devad, regnum);
>         } else if (phydev->is_c45) {
>                 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
> @@ -444,7 +444,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
>         if (regnum > (u16)~0 || devad > 32)
>                 return -EINVAL;
>
> -       if (phydev->drv->write_mmd) {
> +       if (phydev->drv && phydev->drv->write_mmd) {
>                 ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
>         } else if (phydev->is_c45) {
>                 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
> --
> 2.17.1
>

Sorry,
-Vladimir

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

* Re: [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver
  2020-01-16 17:48 ` Vladimir Oltean
@ 2020-01-16 17:52   ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2020-01-16 17:52 UTC (permalink / raw)
  To: Vladimir Oltean, David S. Miller, Russell King - ARM Linux admin,
	Andrew Lunn, Heiner Kallweit
  Cc: netdev, Alex Marginean

On 1/16/20 9:48 AM, Vladimir Oltean wrote:
> On Thu, 16 Jan 2020 at 19:46, Vladimir Oltean <olteanv@gmail.com> wrote:
>>
>> From: Alex Marginean <alexandru.marginean@nxp.com>
>>
>> The APIs can be used by Ethernet drivers without actually loading a PHY
>> driver. This may become more widespread in the future with 802.3z
>> compatible MAC PCS devices being locally driven by the MAC driver when
>> configuring for a PHY mode with in-band negotiation.
>>
>> Check that drv is not NULL before reading from it.
>>
>> Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
>> ---
> 
> Ugh. Can I just add here:
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> 
> without resending?

That's a tag that patchwork understands, so yes, that works:

http://patchwork.ozlabs.org/patch/1224348/mbox/

> 
>> If this hasn't been reported by now I assume it wasn't an issue so far.
>> So I've targeted the patch for net-next and not provided a Fixes: tag.
>>
>>  drivers/net/phy/phy-core.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
>> index 769a076514b0..a4d2d59fceca 100644
>> --- a/drivers/net/phy/phy-core.c
>> +++ b/drivers/net/phy/phy-core.c
>> @@ -387,7 +387,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
>>         if (regnum > (u16)~0 || devad > 32)
>>                 return -EINVAL;
>>
>> -       if (phydev->drv->read_mmd) {
>> +       if (phydev->drv && phydev->drv->read_mmd) {
>>                 val = phydev->drv->read_mmd(phydev, devad, regnum);
>>         } else if (phydev->is_c45) {
>>                 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
>> @@ -444,7 +444,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
>>         if (regnum > (u16)~0 || devad > 32)
>>                 return -EINVAL;
>>
>> -       if (phydev->drv->write_mmd) {
>> +       if (phydev->drv && phydev->drv->write_mmd) {
>>                 ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
>>         } else if (phydev->is_c45) {
>>                 u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
>> --
>> 2.17.1
>>
> 
> Sorry,
> -Vladimir
> 


-- 
Florian

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

* Re: [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver
  2020-01-16 17:46 [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver Vladimir Oltean
  2020-01-16 17:48 ` Vladimir Oltean
@ 2020-01-16 20:47 ` Heiner Kallweit
  2020-01-16 20:51   ` Florian Fainelli
  2020-01-20  9:08 ` David Miller
  2 siblings, 1 reply; 6+ messages in thread
From: Heiner Kallweit @ 2020-01-16 20:47 UTC (permalink / raw)
  To: Vladimir Oltean, davem, linux, andrew, f.fainelli; +Cc: netdev, Alex Marginean

On 16.01.2020 18:46, Vladimir Oltean wrote:
> From: Alex Marginean <alexandru.marginean@nxp.com>
> 
> The APIs can be used by Ethernet drivers without actually loading a PHY
> driver. This may become more widespread in the future with 802.3z
> compatible MAC PCS devices being locally driven by the MAC driver when
> configuring for a PHY mode with in-band negotiation.
> 
> Check that drv is not NULL before reading from it.
> 
If there's no dedicated PHY driver, then the genphy driver is bound.
I think therefore we don't face issues with the current code.
But the change looks reasonable.

> Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>
> ---
> If this hasn't been reported by now I assume it wasn't an issue so far.
> So I've targeted the patch for net-next and not provided a Fixes: tag.
> 
>  drivers/net/phy/phy-core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
> index 769a076514b0..a4d2d59fceca 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -387,7 +387,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
>  	if (regnum > (u16)~0 || devad > 32)
>  		return -EINVAL;
>  
> -	if (phydev->drv->read_mmd) {
> +	if (phydev->drv && phydev->drv->read_mmd) {
>  		val = phydev->drv->read_mmd(phydev, devad, regnum);
>  	} else if (phydev->is_c45) {
>  		u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
> @@ -444,7 +444,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
>  	if (regnum > (u16)~0 || devad > 32)
>  		return -EINVAL;
>  
> -	if (phydev->drv->write_mmd) {
> +	if (phydev->drv && phydev->drv->write_mmd) {
>  		ret = phydev->drv->write_mmd(phydev, devad, regnum, val);
>  	} else if (phydev->is_c45) {
>  		u32 addr = MII_ADDR_C45 | (devad << 16) | (regnum & 0xffff);
> 


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

* Re: [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver
  2020-01-16 20:47 ` Heiner Kallweit
@ 2020-01-16 20:51   ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2020-01-16 20:51 UTC (permalink / raw)
  To: Heiner Kallweit, Vladimir Oltean, davem, linux, andrew
  Cc: netdev, Alex Marginean

On 1/16/20 12:47 PM, Heiner Kallweit wrote:
> On 16.01.2020 18:46, Vladimir Oltean wrote:
>> From: Alex Marginean <alexandru.marginean@nxp.com>
>>
>> The APIs can be used by Ethernet drivers without actually loading a PHY
>> driver. This may become more widespread in the future with 802.3z
>> compatible MAC PCS devices being locally driven by the MAC driver when
>> configuring for a PHY mode with in-band negotiation.
>>
>> Check that drv is not NULL before reading from it.
>>
> If there's no dedicated PHY driver, then the genphy driver is bound.
> I think therefore we don't face issues with the current code.
> But the change looks reasonable.

You can unbind the driver from sysfs and observe the problem.
-- 
Florian

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

* Re: [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver
  2020-01-16 17:46 [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver Vladimir Oltean
  2020-01-16 17:48 ` Vladimir Oltean
  2020-01-16 20:47 ` Heiner Kallweit
@ 2020-01-20  9:08 ` David Miller
  2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2020-01-20  9:08 UTC (permalink / raw)
  To: olteanv
  Cc: linux, andrew, f.fainelli, hkallweit1, netdev, alexandru.marginean

From: Vladimir Oltean <olteanv@gmail.com>
Date: Thu, 16 Jan 2020 19:46:28 +0200

> From: Alex Marginean <alexandru.marginean@nxp.com>
> 
> The APIs can be used by Ethernet drivers without actually loading a PHY
> driver. This may become more widespread in the future with 802.3z
> compatible MAC PCS devices being locally driven by the MAC driver when
> configuring for a PHY mode with in-band negotiation.
> 
> Check that drv is not NULL before reading from it.
> 
> Signed-off-by: Alex Marginean <alexandru.marginean@nxp.com>

Applied, thank you.

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

end of thread, other threads:[~2020-01-20  9:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 17:46 [PATCH net-next] net: phy: don't crash in phy_read/_write_mmd without a PHY driver Vladimir Oltean
2020-01-16 17:48 ` Vladimir Oltean
2020-01-16 17:52   ` Florian Fainelli
2020-01-16 20:47 ` Heiner Kallweit
2020-01-16 20:51   ` Florian Fainelli
2020-01-20  9:08 ` 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).