Re: [PATCH net] net: lan966x: fix kernel oops on ioctl when I/F is down

From: Andrew Lunn
Date: Mon Mar 28 2022 - 16:48:15 EST


> > So rather than testing of running, it would be better to test if the
> > phydev is NULL or not.
>
> What about the following:
>
> static int lan966x_port_ioctl(struct net_device *dev, struct ifreq *ifr,
> int cmd)
> {
> struct lan966x_port *port = netdev_priv(dev);
>
> if (!phy_has_hwtstamp(dev->phydev) && port->lan966x->ptp) {
> switch (cmd) {
> case SIOCSHWTSTAMP:
> return lan966x_ptp_hwtstamp_set(port, ifr);
> case SIOCGHWTSTAMP:
> return lan966x_ptp_hwtstamp_get(port, ifr);
> }
> }
>
> if (!dev->phydev)
> return -ENODEV;
>
> return phy_mii_ioctl(dev->phydev, ifr, cmd);

Yes, that is good.

Andrew