Re: [RFC PATCH net-next 10/12] net: lan966x: add port module support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Sep 20, 2021 at 11:52:16AM +0200, Horatiu Vultur wrote:
> +static void lan966x_cleanup_ports(struct lan966x *lan966x)
> +{
> +	struct lan966x_port *port;
> +	int portno;
> +
> +	for (portno = 0; portno < lan966x->num_phys_ports; portno++) {
> +		port = lan966x->ports[portno];
> +		if (!port)
> +			continue;
> +
> +		if (port->phylink) {
> +			rtnl_lock();
> +			lan966x_port_stop(port->dev);
> +			rtnl_unlock();
> +			port->phylink = NULL;

This leaks the phylink structure. You need to call phylink_destroy().

>  static int lan966x_probe_port(struct lan966x *lan966x, u8 port,
>  			      phy_interface_t phy_mode)
>  {
>  	struct lan966x_port *lan966x_port;
> +	struct phylink *phylink;
> +	struct net_device *dev;
> +	int err;
>  
>  	if (port >= lan966x->num_phys_ports)
>  		return -EINVAL;
>  
> -	lan966x_port = devm_kzalloc(lan966x->dev, sizeof(*lan966x_port),
> -				    GFP_KERNEL);
> +	dev = devm_alloc_etherdev_mqs(lan966x->dev,
> +				      sizeof(struct lan966x_port), 8, 1);
> +	if (!dev)
> +		return -ENOMEM;
>  
> +	SET_NETDEV_DEV(dev, lan966x->dev);
> +	lan966x_port = netdev_priv(dev);
> +	lan966x_port->dev = dev;
>  	lan966x_port->lan966x = lan966x;
>  	lan966x_port->chip_port = port;
>  	lan966x_port->pvid = PORT_PVID;
>  	lan966x->ports[port] = lan966x_port;
>  
> +	dev->max_mtu = ETH_MAX_MTU;
> +
> +	dev->netdev_ops = &lan966x_port_netdev_ops;
> +	dev->needed_headroom = IFH_LEN * sizeof(u32);
> +
> +	err = register_netdev(dev);
> +	if (err) {
> +		dev_err(lan966x->dev, "register_netdev failed\n");
> +		goto err_register_netdev;
> +	}

register_netdev() publishes the network device.

> +
> +	lan966x_port->phylink_config.dev = &lan966x_port->dev->dev;
> +	lan966x_port->phylink_config.type = PHYLINK_NETDEV;
> +	lan966x_port->phylink_config.pcs_poll = true;
> +
> +	phylink = phylink_create(&lan966x_port->phylink_config,
> +				 lan966x_port->fwnode,
> +				 phy_mode,
> +				 &lan966x_phylink_mac_ops);

phylink_create() should always be called _prior_ to the network device
being published. In any case...

> +	if (IS_ERR(phylink))
> +		return PTR_ERR(phylink);

If this fails, this function returns an error, but leaves the network
device published - which is a bug in itself.

> +static void lan966x_phylink_mac_link_down(struct phylink_config *config,
> +					  unsigned int mode,
> +					  phy_interface_t interface)
> +{

Hmm? Shouldn't this do something?

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux