Re: [PATCH v2 net-next 1/4] net/ethtool: add netlink interface for the PLCA RS

From: Piergiorgio Beruto
Date: Mon Dec 05 2022 - 04:37:26 EST


On Mon, Dec 05, 2022 at 09:28:51AM +0000, Russell King (Oracle) wrote:
> On Mon, Dec 05, 2022 at 02:41:35AM +0100, Piergiorgio Beruto wrote:
> > +int ethnl_set_plca_cfg(struct sk_buff *skb, struct genl_info *info)
> > +{
> > + struct ethnl_req_info req_info = {};
> > + struct nlattr **tb = info->attrs;
> > + const struct ethtool_phy_ops *ops;
> > + struct phy_plca_cfg plca_cfg;
> > + struct net_device *dev;
> > +
> > + bool mod = false;
> > + int ret;
> > +
> > + ret = ethnl_parse_header_dev_get(&req_info,
> > + tb[ETHTOOL_A_PLCA_HEADER],
> > + genl_info_net(info), info->extack,
> > + true);
> > + if (ret < 0)
> > + return ret;
> > +
> > + dev = req_info.dev;
> > +
> > + // check that the PHY device is available and connected
> > + if (!dev->phydev) {
> > + ret = -EOPNOTSUPP;
> > + goto out;
> > + }
>
> This check should really be done under the RTNL lock. phydevs can come
> and go with SFP cages.
>
> > +
> > + rtnl_lock();
Good point Russell, I'll fix that. And I wish to seize the opportunity
to remark that the same problem may be present in cabletest.c
(see below).

Maybe we should post a patch to fix that?

Thanks,
Piergiorgio

int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
{
struct ethnl_req_info req_info = {};
const struct ethtool_phy_ops *ops;
struct nlattr **tb = info->attrs;
struct net_device *dev;
int ret;

ret = ethnl_parse_header_dev_get(&req_info,
tb[ETHTOOL_A_CABLE_TEST_HEADER],
genl_info_net(info), info->extack,
true);
if (ret < 0)
return ret;

dev = req_info.dev;
if (!dev->phydev) {
ret = -EOPNOTSUPP;
goto out_dev_put;
}

rtnl_lock();