From: Christian Marangi <ansuelsmth@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
Vladimir Oltean <olteanv@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
upstream@airoha.com
Subject: Re: [net-next PATCH v3 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY
Date: Wed, 6 Nov 2024 19:11:18 +0100 [thread overview]
Message-ID: <672bb14a.7b0a0220.fded0.9db6@mx.google.com> (raw)
In-Reply-To: <8e5fd144-2325-43ff-b2b8-92d7f5910392@lunn.ch>
On Wed, Nov 06, 2024 at 05:19:03PM +0100, Andrew Lunn wrote:
> > +static const u8 dsa_r50ohm_table[] = {
> > + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
> > + 127, 127, 127, 127, 127, 127, 127, 126, 122, 117,
> > + 112, 109, 104, 101, 97, 94, 90, 88, 84, 80,
> > + 78, 74, 72, 68, 66, 64, 61, 58, 56, 53,
> > + 51, 48, 47, 44, 42, 40, 38, 36, 34, 32,
> > + 31, 28, 27, 24, 24, 22, 20, 18, 16, 16,
> > + 14, 12, 11, 9
> > +};
> > +
> > +static int en8855_get_r50ohm_val(struct device *dev, const char *calib_name,
> > + u8 *dest)
> > +{
> > + u32 shift_sel, val;
> > + int ret;
> > + int i;
> > +
> > + ret = nvmem_cell_read_u32(dev, calib_name, &val);
> > + if (ret)
> > + return ret;
> > +
> > + shift_sel = FIELD_GET(AN8855_SWITCH_EFUSE_R50O, val);
> > + for (i = 0; i < ARRAY_SIZE(dsa_r50ohm_table); i++)
> > + if (dsa_r50ohm_table[i] == shift_sel)
> > + break;
>
> Is an exact match expected? Should this be >= so the nearest match is
> found?
>
As strange as this is, yes this is what the original code does.
> > +
> > + if (i < 8 || i >= ARRAY_SIZE(dsa_r50ohm_table))
> > + *dest = dsa_r50ohm_table[25];
> > + else
> > + *dest = dsa_r50ohm_table[i - 8];
> > +
> > + return 0;
> > +}
> > +
> > +static int an8855_probe(struct phy_device *phydev)
> > +{
> > + struct device *dev = &phydev->mdio.dev;
> > + struct device_node *node = dev->of_node;
> > + struct air_an8855_priv *priv;
> > + int ret;
> > +
> > + /* If we don't have a node, skip get calib */
> > + if (!node)
> > + return 0;
>
> phydev->priv will be a NULL pointer, causing problems in
> an8855_config_init()
>
Quite unlikely scenario since for the switch, defining the internal PHY
in an MDIO node is mandatory but yes it's a fragility.
2 solution:
- I check priv in config_init and skip that section
- I always set phydev->priv
Solution 1 is safer (handle case where for some reason
en8855_get_r50ohm_val fails (it's really almost impossible)) but error
prone if the PHY gets extended with other parts and priv starts to gets
used for other thing.
Solution 2 require an extra bool to signal full calibrarion read and is
waste more resource (in case calib is not needed...)
Anyway thanks for the review!
--
Ansuel
next prev parent reply other threads:[~2024-11-06 18:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 12:22 [net-next PATCH v3 0/3] net: dsa: Add Airoha AN8855 support Christian Marangi
2024-11-06 12:22 ` [net-next PATCH v3 1/3] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation Christian Marangi
2024-11-06 12:22 ` [net-next PATCH v3 2/3] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver Christian Marangi
2024-11-07 17:53 ` Christophe JAILLET
2024-11-07 19:36 ` Andrew Lunn
2024-11-08 10:32 ` Christian Marangi
2024-11-08 10:51 ` Russell King (Oracle)
2024-11-06 12:22 ` [net-next PATCH v3 3/3] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY Christian Marangi
2024-11-06 14:54 ` Maxime Chevallier
2024-11-06 18:04 ` Christian Marangi
2024-11-06 16:19 ` Andrew Lunn
2024-11-06 18:11 ` Christian Marangi [this message]
2024-11-07 2:37 ` kernel test robot
2024-11-08 11:09 ` Russell King (Oracle)
2024-11-08 13:09 ` Christian Marangi
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=672bb14a.7b0a0220.fded0.9db6@mx.google.com \
--to=ansuelsmth@gmail.com \
--cc=andrew@lunn.ch \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.bgg@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=upstream@airoha.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.