]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - drivers/net/dsa/realtek-smi-core.c
net: dsa: be compatible with masters which unregister on shutdown
[mirror_ubuntu-jammy-kernel.git] / drivers / net / dsa / realtek-smi-core.c
index 8e49d4f85d48c31da45dd239d994d0cb0ac07d44..dd2f0d6208b3f21465da4ab8b7e5fc4332c0d71b 100644 (file)
@@ -464,16 +464,33 @@ static int realtek_smi_probe(struct platform_device *pdev)
 
 static int realtek_smi_remove(struct platform_device *pdev)
 {
-       struct realtek_smi *smi = dev_get_drvdata(&pdev->dev);
+       struct realtek_smi *smi = platform_get_drvdata(pdev);
+
+       if (!smi)
+               return 0;
 
        dsa_unregister_switch(smi->ds);
        if (smi->slave_mii_bus)
                of_node_put(smi->slave_mii_bus->dev.of_node);
        gpiod_set_value(smi->reset, 1);
 
+       platform_set_drvdata(pdev, NULL);
+
        return 0;
 }
 
+static void realtek_smi_shutdown(struct platform_device *pdev)
+{
+       struct realtek_smi *smi = platform_get_drvdata(pdev);
+
+       if (!smi)
+               return;
+
+       dsa_switch_shutdown(smi->ds);
+
+       platform_set_drvdata(pdev, NULL);
+}
+
 static const struct of_device_id realtek_smi_of_match[] = {
        {
                .compatible = "realtek,rtl8366rb",
@@ -495,6 +512,7 @@ static struct platform_driver realtek_smi_driver = {
        },
        .probe  = realtek_smi_probe,
        .remove = realtek_smi_remove,
+       .shutdown = realtek_smi_shutdown,
 };
 module_platform_driver(realtek_smi_driver);