From: Andrew Lunn <andrew@lunn.ch>
To: Kedareswara rao Appana <appana.durga.rao@xilinx.com>
Cc: robh+dt@kernel.org, mark.rutland@arm.com,
michal.simek@xilinx.com, soren.brinkmann@xilinx.com,
appanad@xilinx.com, f.fainelli@gmail.com, punnaia@xilinx.com,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v6 3/3] net: phy: Add gmiitorgmii converter support
Date: Tue, 16 Aug 2016 18:53:20 +0200 [thread overview]
Message-ID: <20160816165320.GP14446@lunn.ch> (raw)
In-Reply-To: <1470808208-32133-4-git-send-email-appanad@xilinx.com>
> +static int xgmiitorgmii_read_status(struct phy_device *phydev)
> +{
> + struct gmii2rgmii *priv = phydev->priv;
> + u16 val = 0;
> +
> + priv->phy_drv->read_status(phydev);
This can return an error, in which case phydev->speed should not be
trusted.
I've not thought locking all the way through yet. I don't think you
need a lock here, but i need to think about it.
> +
> + val = mdiobus_read(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG);
You should check for an error here.
> + val &= XILINX_GMII2RGMII_SPEED_MASK;
> +
> + if (phydev->speed == SPEED_1000)
> + val |= BMCR_SPEED1000;
> + else if (phydev->speed == SPEED_100)
> + val |= BMCR_SPEED100;
> + else
> + val |= BMCR_SPEED10;
What happens if for example the PHY is an aquantia and has negotiated
SPEED_2500? Some Marvell PHYs can also do odd speeds, like 200Mbps.
You probably want to return an error, rather than silently have things
go wrong.
> +
> + mdiobus_write(phydev->mdio.bus, priv->addr, XILINX_GMII2RGMII_REG, val);
This can also return an error.
> + return 0;
> +}
> +
> +int xgmiitorgmii_probe(struct mdio_device *mdiodev)
> +{
> + struct device *dev = &mdiodev->dev;
> + struct device_node *np = dev->of_node, *phy_node;
> + struct gmii2rgmii *priv;
> +
> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + phy_node = of_parse_phandle(np, "phy-handle", 0);
> + if (IS_ERR(phy_node)) {
> + dev_err(dev, "Couldn't parse phy-handle\n");
> + return -ENODEV;
> + }
> +
> + priv->phy_dev = of_phy_find_device(phy_node);
> + if (!priv->phy_dev) {
> + dev_info(dev, "Couldn't find phydev\n");
> + return -EPROBE_DEFER;
> + }
> +
> + priv->addr = mdiodev->addr;
> + priv->phy_drv = priv->phy_dev->drv;
> + memcpy(&priv->conv_phy_drv, priv->phy_dev->drv,
> + sizeof(struct phy_driver));
> + priv->conv_phy_drv.read_status = xgmiitorgmii_read_status;
> + priv->phy_dev->priv = priv;
> + priv->phy_dev->drv = &priv->conv_phy_drv;
So from this point onward, the phy driver depends on the memory
allocated by this driver. If this driver goes away, freeing its
memory, the next call to read_status() is going to have a problem.
Also, i think this assignment should take the phy lock, just to be
safe.
There also needs to be some thought into what happens if the phy
driver is unloaded. Should this driver take a reference on the phy
driver to prevent that?
Andrew
next prev parent reply other threads:[~2016-08-16 16:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-10 5:50 [PATCH v6 0/3] net: phy: Add xilinx gmiitorgmii converter support Kedareswara rao Appana
2016-08-10 5:50 ` [PATCH v6 1/3] net: Add mask for Control register 10Mbps speed Kedareswara rao Appana
2016-08-10 5:50 ` [PATCH v6 2/3] Documentation: DT: net: Add Xilinx gmiitorgmii converter device tree binding documentation Kedareswara rao Appana
[not found] ` <1470808208-32133-3-git-send-email-appanad-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>
2016-08-10 22:29 ` Rob Herring
2016-08-10 5:50 ` [PATCH v6 3/3] net: phy: Add gmiitorgmii converter support Kedareswara rao Appana
2016-08-16 16:53 ` Andrew Lunn [this message]
2016-08-18 15:53 ` Appana Durga Kedareswara Rao
[not found] ` <1470808208-32133-1-git-send-email-appanad-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>
2016-08-12 23:57 ` [PATCH v6 0/3] net: phy: Add xilinx " 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=20160816165320.GP14446@lunn.ch \
--to=andrew@lunn.ch \
--cc=appana.durga.rao@xilinx.com \
--cc=appanad@xilinx.com \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=michal.simek@xilinx.com \
--cc=netdev@vger.kernel.org \
--cc=punnaia@xilinx.com \
--cc=robh+dt@kernel.org \
--cc=soren.brinkmann@xilinx.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).