diff mbox series

[v2,net,7/8] net: mscc: ocelot: unregister net devices on unbind

Message ID 20200918010730.2911234-8-olteanv@gmail.com
State New
Headers show
Series [v2,net,1/8] net: mscc: ocelot: fix race condition with TX timestamping | expand

Commit Message

Vladimir Oltean Sept. 18, 2020, 1:07 a.m. UTC
From: Vladimir Oltean <vladimir.oltean@nxp.com>

This driver was not unregistering its network interfaces on unbind.
Now it is.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
Changes in v2:
No longer call mscc_ocelot_release_ports from the regular exit path of
mscc_ocelot_init_ports, which was incorrect.

 drivers/net/ethernet/mscc/ocelot_vsc7514.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Florian Fainelli Sept. 18, 2020, 2:34 a.m. UTC | #1
On 9/17/2020 6:07 PM, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>
> 
> This driver was not unregistering its network interfaces on unbind.
> Now it is.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Alexandre Belloni Sept. 18, 2020, 3:28 p.m. UTC | #2
On 18/09/2020 04:07:29+0300, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>

> 

> This driver was not unregistering its network interfaces on unbind.

> Now it is.

> 

> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

> Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>


Tested-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>


> ---

> Changes in v2:

> No longer call mscc_ocelot_release_ports from the regular exit path of

> mscc_ocelot_init_ports, which was incorrect.

> 

>  drivers/net/ethernet/mscc/ocelot_vsc7514.c | 21 +++++++++++++++++++++

>  1 file changed, 21 insertions(+)

> 

> diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c

> index ff4a01424953..252c49b5f22b 100644

> --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c

> +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c

> @@ -896,6 +896,26 @@ static struct ptp_clock_info ocelot_ptp_clock_info = {

>  	.enable		= ocelot_ptp_enable,

>  };

>  

> +static void mscc_ocelot_release_ports(struct ocelot *ocelot)

> +{

> +	int port;

> +

> +	for (port = 0; port < ocelot->num_phys_ports; port++) {

> +		struct ocelot_port_private *priv;

> +		struct ocelot_port *ocelot_port;

> +

> +		ocelot_port = ocelot->ports[port];

> +		if (!ocelot_port)

> +			continue;

> +

> +		priv = container_of(ocelot_port, struct ocelot_port_private,

> +				    port);

> +

> +		unregister_netdev(priv->dev);

> +		free_netdev(priv->dev);

> +	}

> +}

> +

>  static int mscc_ocelot_init_ports(struct platform_device *pdev,

>  				  struct device_node *ports)

>  {

> @@ -1132,6 +1152,7 @@ static int mscc_ocelot_remove(struct platform_device *pdev)

>  	struct ocelot *ocelot = platform_get_drvdata(pdev);

>  

>  	ocelot_deinit_timestamp(ocelot);

> +	mscc_ocelot_release_ports(ocelot);

>  	ocelot_deinit(ocelot);

>  	unregister_switchdev_blocking_notifier(&ocelot_switchdev_blocking_nb);

>  	unregister_switchdev_notifier(&ocelot_switchdev_nb);

> -- 

> 2.25.1

> 


-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
index ff4a01424953..252c49b5f22b 100644
--- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c
+++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c
@@ -896,6 +896,26 @@  static struct ptp_clock_info ocelot_ptp_clock_info = {
 	.enable		= ocelot_ptp_enable,
 };
 
+static void mscc_ocelot_release_ports(struct ocelot *ocelot)
+{
+	int port;
+
+	for (port = 0; port < ocelot->num_phys_ports; port++) {
+		struct ocelot_port_private *priv;
+		struct ocelot_port *ocelot_port;
+
+		ocelot_port = ocelot->ports[port];
+		if (!ocelot_port)
+			continue;
+
+		priv = container_of(ocelot_port, struct ocelot_port_private,
+				    port);
+
+		unregister_netdev(priv->dev);
+		free_netdev(priv->dev);
+	}
+}
+
 static int mscc_ocelot_init_ports(struct platform_device *pdev,
 				  struct device_node *ports)
 {
@@ -1132,6 +1152,7 @@  static int mscc_ocelot_remove(struct platform_device *pdev)
 	struct ocelot *ocelot = platform_get_drvdata(pdev);
 
 	ocelot_deinit_timestamp(ocelot);
+	mscc_ocelot_release_ports(ocelot);
 	ocelot_deinit(ocelot);
 	unregister_switchdev_blocking_notifier(&ocelot_switchdev_blocking_nb);
 	unregister_switchdev_notifier(&ocelot_switchdev_nb);