netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Feiyang Chen <chenfeiyang@loongson.cn>
Cc: andrew@lunn.ch, hkallweit1@gmail.com, peppe.cavallaro@st.com,
	alexandre.torgue@foss.st.com, joabreu@synopsys.com,
	chenhuacai@loongson.cn, dongbiao@loongson.cn,
	loongson-kernel@lists.loongnix.cn, netdev@vger.kernel.org,
	loongarch@lists.linux.dev, chris.chenfeiyang@gmail.com
Subject: Re: [RFC PATCH 01/10] net: phy: Add driver for Loongson PHY
Date: Thu, 13 Jul 2023 08:53:42 +0100	[thread overview]
Message-ID: <ZK+thg7xIKt7b8X+@shell.armlinux.org.uk> (raw)
In-Reply-To: <be1874e517f4f4cc50906f18689a0add3594c2e0.1689215889.git.chenfeiyang@loongson.cn>

On Thu, Jul 13, 2023 at 10:46:53AM +0800, Feiyang Chen wrote:
> +#define PHY_ID_LS7A2000		0x00061ce0
> +#define GNET_REV_LS7A2000	0x00
> +
> +static int ls7a2000_config_aneg(struct phy_device *phydev)
> +{
> +	if (phydev->speed == SPEED_1000)
> +		phydev->autoneg = AUTONEG_ENABLE;
> +
> +	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
> +	    phydev->advertising) ||
> +	    linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
> +	    phydev->advertising) ||
> +	    linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
> +	    phydev->advertising))
> +	    return genphy_config_aneg(phydev);

While it's fine to use four spaces within the if () expression, this
"return" should be indented with a tab.

> +
> +	netdev_info(phydev->attached_dev, "Parameter Setting Error\n");

Does this give the opportunity for userspace to spam the kernel log?
E.g. by a daemon repeatedly trying to set link parameters? Should it
be rate limited?

> +	return -1;

Sigh, not this laziness disease yet again. -1 is -EPERM. Return a
real errno code.

> +int ls7a2000_match_phy_device(struct phy_device *phydev)
> +{
> +	struct net_device *ndev;
> +	struct pci_dev *pdev;
> +
> +	if ((phydev->phy_id & 0xfffffff0) != PHY_ID_LS7A2000)
> +		return 0;

	if (!phy_id_compare(phydev->phy_id, PHY_ID_LS7A2000, 0xfffffff0))
		return 0;

> +
> +	ndev = phydev->mdio.bus->priv;

This doesn't look safe to me - you're assuming that if the PHY ID
above matches, that the MDIO bus' private data is something you know
which is far from guaranteed.

The mdio bus has a parent device - that would be a safer route to
check what the parent device is, provided the mdio bus is created so
that it's a child of the parent PCI device.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  parent reply	other threads:[~2023-07-13  7:54 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13  2:46 [RFC PATCH 00/10] net: phy/stmmac: Add Loongson platform support Feiyang Chen
2023-07-13  2:46 ` [RFC PATCH 01/10] net: phy: Add driver for Loongson PHY Feiyang Chen
2023-07-13  4:00   ` Andrew Lunn
2023-07-14  2:15     ` Feiyang Chen
2023-07-14  4:19       ` Andrew Lunn
2023-07-17  2:43         ` Feiyang Chen
2023-07-17 12:22           ` Andrew Lunn
2023-07-21  3:31             ` Feiyang Chen
2023-07-21  9:04               ` Andrew Lunn
2023-07-25  2:02                 ` Feiyang Chen
2023-07-25 17:20                   ` Andrew Lunn
2023-07-13  7:53   ` Russell King (Oracle) [this message]
2023-07-14  2:41     ` Feiyang Chen
2023-07-13  2:46 ` [RFC PATCH 02/10] net: stmmac: Pass stmmac_priv and chan in some callbacks Feiyang Chen
2023-07-13  4:02   ` Andrew Lunn
2023-07-14  2:16     ` Feiyang Chen
2023-07-13  2:46 ` [RFC PATCH 03/10] net: stmmac: dwmac1000: Allow platforms to choose some register offsets Feiyang Chen
2023-07-13  2:46 ` [RFC PATCH 04/10] net: stmmac: dwmac1000: Add multi-channel support Feiyang Chen
2023-07-13  2:48 ` [RFC PATCH 05/10] net: stmmac: dwmac1000: Add 64-bit DMA support Feiyang Chen
2023-07-13  2:48 ` [RFC PATCH 06/10] net: stmmac: dwmac1000: Add Loongson register definitions Feiyang Chen
2023-07-13  2:48 ` [RFC PATCH 07/10] net: stmmac: Add Loongson HWIF entry Feiyang Chen
2023-07-13  2:48 ` [RFC PATCH 08/10] net: stmmac: dwmac-loongson: Add LS7A support Feiyang Chen
2023-07-13  2:48 ` [RFC PATCH 09/10] net: stmmac: dwmac-loongson: Add 64-bit DMA and multi-vector support Feiyang Chen
2023-07-13  2:49 ` [RFC PATCH 10/10] net: stmmac: dwmac-loongson: Add GNET support Feiyang Chen
2023-07-13  4:07   ` Andrew Lunn
2023-07-14  2:24     ` Feiyang Chen
2023-07-14  4:26       ` Andrew Lunn
2023-07-14  8:52         ` Russell King (Oracle)
2023-07-14  8:45       ` Russell King (Oracle)
2023-07-17  7:54         ` Feiyang Chen
2023-07-13  8:06   ` Russell King (Oracle)
2023-07-14  2:27     ` Feiyang Chen
2023-07-14  4:22       ` Andrew Lunn
2023-07-13  4:09 ` [RFC PATCH 00/10] net: phy/stmmac: Add Loongson platform support Andrew Lunn
2023-07-14  2:16   ` Feiyang Chen
2023-07-14  8:39     ` Russell King (Oracle)
2023-07-16 14:59       ` Andrew Lunn
2023-07-17  2:57         ` Feiyang Chen

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=ZK+thg7xIKt7b8X+@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew@lunn.ch \
    --cc=chenfeiyang@loongson.cn \
    --cc=chenhuacai@loongson.cn \
    --cc=chris.chenfeiyang@gmail.com \
    --cc=dongbiao@loongson.cn \
    --cc=hkallweit1@gmail.com \
    --cc=joabreu@synopsys.com \
    --cc=loongarch@lists.linux.dev \
    --cc=loongson-kernel@lists.loongnix.cn \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    /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).