From: Jakub Kicinski <kuba@kernel.org>
To: Maxime Chevallier <maxime.chevallier@bootlin.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com,
"Andrew Lunn" <andrew@lunn.ch>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Russell King" <linux@armlinux.org.uk>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Simon Horman" <horms@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v3 1/3] net: netdevsim: Add PHY support in netdevsim
Date: Fri, 11 Jul 2025 16:55:41 -0700 [thread overview]
Message-ID: <20250711165541.586f51e8@kernel.org> (raw)
In-Reply-To: <20250710062248.378459-2-maxime.chevallier@bootlin.com>
On Thu, 10 Jul 2025 08:22:45 +0200 Maxime Chevallier wrote:
> @@ -1098,6 +1101,10 @@ static int __init nsim_module_init(void)
> {
> int err;
>
> + err = nsim_phy_drv_register();
> + if (err)
> + return err;
> +
> err = nsim_dev_init();
> if (err)
> return err;
I think you're missing error handling in this function if something
after drv_register fails.
> @@ -1124,6 +1131,7 @@ static void __exit nsim_module_exit(void)
> rtnl_link_unregister(&nsim_link_ops);
> nsim_bus_exit();
> nsim_dev_exit();
> + nsim_phy_drv_unregister();
> }
> +free_mdiobus:
> + atomic_dec(&bus_num);
> + mdiobus_free(mb->mii);
> +free_pdev:
> + platform_device_unregister(mb->pdev);
> +free_mb:
Others have added netdevsim code so the entire code base doesn't follow
what I'm about to say, but if you dont mind indulging my personal coding
style - error handling labels on a path disjoint from the success path
should be prefixed with err_$first-undo-action. If the error handling
shares the path with success the label prefix should be exit_$..
You can look at drivers/net/netdevsim/bpf.c for examples
> + kfree(mb);
> +
> + return NULL;
> +}
> +
> +static ssize_t
> +nsim_phy_add_write(struct file *file, const char __user *data,
> + size_t count, loff_t *ppos)
> +{
> + struct net_device *dev = file->private_data;
> + struct netdevsim *ns = netdev_priv(dev);
> + struct nsim_phy_device *ns_phy;
> + struct phy_device *pphy;
> + u32 parent_id;
> + char buf[10];
> + ssize_t ret;
> + int err;
> +
> + if (*ppos != 0)
> + return 0;
> +
> + if (count >= sizeof(buf))
> + return -ENOSPC;
> +
> + ret = copy_from_user(buf, data, count);
> + if (ret)
> + return -EFAULT;
> + buf[count] = '\0';
> +
> + ret = kstrtouint(buf, 10, &parent_id);
> + if (ret)
> + return -EINVAL;
> +
> + ns_phy = nsim_phy_register();
> + if (IS_ERR(ns_phy))
> + return PTR_ERR(ns_phy);
> +
> + if (!parent_id) {
> + if (!dev->phydev) {
> + err = phy_connect_direct(dev, ns_phy->phy, nsim_adjust_link,
> + PHY_INTERFACE_MODE_NA);
> + if (err)
> + return err;
> +
> + phy_attached_info(ns_phy->phy);
> +
> + phy_start(ns_phy->phy);
> + } else {
> + phy_link_topo_add_phy(dev, ns_phy->phy, PHY_UPSTREAM_MAC, dev);
> + }
> + } else {
> + pphy = phy_link_topo_get_phy(dev, parent_id);
> + if (!pphy)
> + return -EINVAL;
> +
> + phy_link_topo_add_phy(dev, ns_phy->phy, PHY_UPSTREAM_PHY, pphy);
> + }
> +
> + nsim_phy_debugfs_create(ns->nsim_dev_port, ns_phy);
> +
> + list_add(&ns_phy->node, &ns->nsim_dev->phy_list);
No locks needed.. for any of this.. ?
--
pw-bot: cr
next prev parent reply other threads:[~2025-07-11 23:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 6:22 [PATCH net-next v3 0/3] netdevsim: add support for PHY devices Maxime Chevallier
2025-07-10 6:22 ` [PATCH net-next v3 1/3] net: netdevsim: Add PHY support in netdevsim Maxime Chevallier
2025-07-11 23:55 ` Jakub Kicinski [this message]
2025-07-15 6:08 ` Maxime Chevallier
2025-07-12 16:54 ` Andrew Lunn
2025-07-15 6:05 ` Maxime Chevallier
2025-07-15 13:23 ` Andrew Lunn
2025-07-15 13:56 ` Maxime Chevallier
2025-07-15 15:16 ` Andrew Lunn
2025-07-10 6:22 ` [PATCH net-next v3 2/3] selftests: ethtool: Drop the unused old_netdevs variable Maxime Chevallier
2025-07-10 6:22 ` [PATCH net-next v3 3/3] selftests: ethtool: Introduce ethernet PHY selftests on netdevsim Maxime Chevallier
2025-07-11 23:58 ` Jakub Kicinski
2025-07-15 5:45 ` Maxime Chevallier
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=20250711165541.586f51e8@kernel.org \
--to=kuba@kernel.org \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.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).