netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Russell King - ARM Linux admin <linux@armlinux.org.uk>
To: Jeremy Linton <jeremy.linton@arm.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH RFC 7/7] net: phy: read MMD ID from all present MMDs
Date: Tue, 26 May 2020 16:46:00 +0100	[thread overview]
Message-ID: <20200526154600.GC1551@shell.armlinux.org.uk> (raw)
In-Reply-To: <5bce099a-1bbe-d3ee-7cc1-50ff5e8e25ca@arm.com>

On Tue, May 26, 2020 at 10:35:46AM -0500, Jeremy Linton wrote:
> Hi,
> 
> On 5/26/20 9:31 AM, Russell King wrote:
> > Expand the device_ids[] array to allow all MMD IDs to be read rather
> > than just the first 8 MMDs, but only read the ID if the MDIO_STAT2
> > register reports that a device really is present here for these new
> > devices to maintain compatibility with our current behaviour.
> > 
> > 88X3310 PHY vendor MMDs do are marked as present in the
> > devices_in_package, but do not contain IEE 802.3 compatible register
> > sets in their lower space.  This avoids reading incorrect values as MMD
> > identifiers.
> > 
> > Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> > ---
> >   drivers/net/phy/phy_device.c | 14 ++++++++++++++
> >   include/linux/phy.h          |  2 +-
> >   2 files changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 1c948bbf4fa0..92742c7be80f 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -773,6 +773,20 @@ static int get_phy_c45_ids(struct mii_bus *bus, int addr, u32 *phy_id,
> >   		if (!(devs_in_pkg & (1 << i)))
> >   			continue;
> > +		if (i >= 8) {
> > +			/* Only probe the MMD ID for MMDs >= 8 if they report
> > +			 * that they are present. We have at least one PHY that
> > +			 * reports MMD presence in devs_in_pkg, but does not
> > +			 * contain valid IEEE 802.3 ID registers in some MMDs.
> > +			 */
> > +			ret = phy_c45_probe_present(bus, addr, i);
> > +			if (ret < 0)
> > +				return ret;
> > +
> > +			if (!ret)
> > +				continue;
> > +		}
> > +
> >   		phy_reg = mdiobus_c45_read(bus, addr, i, MII_PHYSID1);
> >   		if (phy_reg < 0)
> >   			return -EIO;
> > diff --git a/include/linux/phy.h b/include/linux/phy.h
> > index 0d41c710339a..3325dd8fb9ac 100644
> > --- a/include/linux/phy.h
> > +++ b/include/linux/phy.h
> > @@ -361,7 +361,7 @@ enum phy_state {
> >   struct phy_c45_device_ids {
> >   	u32 devices_in_package;
> >   	u32 mmds_present;
> > -	u32 device_ids[8];
> > +	u32 device_ids[MDIO_MMD_NUM];
> 
> You have a array overflow/invalid access if you don't do this earlier in
> 4/7.

I'm very sorry, but you are mistaken - there is no overflow.

The overflow would happen if I'd changed the _second_ loop in
get_phy_c45_ids(), but that still relies upon the size of this
array.  In fact, everywhere that the device_ids array is indexed
with a for() loop, the maximum bound is defined by the element
size of the array.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC for 0.8m (est. 1762m) line in suburbia: sync at 13.1Mbps down 424kbps up

  reply	other threads:[~2020-05-26 15:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 14:29 [PATCH RFC 0/7] Clause 45 PHY probing cleanups Russell King - ARM Linux admin
2020-05-26 14:31 ` [PATCH RFC 1/7] net: mdiobus: add clause 45 mdiobus accessors Russell King
2020-05-26 14:39   ` Andrew Lunn
2020-05-26 15:21     ` Russell King - ARM Linux admin
2020-05-26 14:31 ` [PATCH RFC 2/7] net: phy: clean up cortina workaround Russell King
2020-05-26 14:31 ` [PATCH RFC 3/7] net: phy: clean up PHY ID reading Russell King
2020-05-26 15:38   ` Jeremy Linton
2020-05-26 15:46     ` Russell King - ARM Linux admin
2020-05-26 14:31 ` [PATCH RFC 4/7] net: phy: add support for probing MMDs >= 8 for devices-in-package Russell King
2020-05-26 17:14   ` Russell King - ARM Linux admin
2020-05-26 17:20     ` Jeremy Linton
2020-05-26 17:53       ` Russell King - ARM Linux admin
2020-05-26 14:31 ` [PATCH RFC 5/7] net: phy: set devices_in_package only after validation Russell King
2020-05-26 15:39   ` Jeremy Linton
2020-05-26 15:50     ` Russell King - ARM Linux admin
2020-05-26 16:33       ` Russell King - ARM Linux admin
2020-05-26 14:31 ` [PATCH RFC 6/7] net: phy: split devices_in_package Russell King
2020-05-26 15:39   ` Jeremy Linton
2020-05-26 15:47     ` Russell King - ARM Linux admin
2020-05-26 16:00       ` Russell King - ARM Linux admin
2020-05-26 14:31 ` [PATCH RFC 7/7] net: phy: read MMD ID from all present MMDs Russell King
2020-05-26 15:35   ` Jeremy Linton
2020-05-26 15:46     ` Russell King - ARM Linux admin [this message]
2020-05-26 15:43 ` [PATCH RFC 0/7] Clause 45 PHY probing cleanups Russell King - ARM Linux admin

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=20200526154600.GC1551@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=jeremy.linton@arm.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).