net: dsa: be compatible with masters which unregister on shutdown
[platform/kernel/linux-starfive.git] / drivers / net / dsa / lan9303_i2c.c
index 9bffaef..8ca4713 100644 (file)
@@ -67,13 +67,28 @@ static int lan9303_i2c_probe(struct i2c_client *client,
 
 static int lan9303_i2c_remove(struct i2c_client *client)
 {
-       struct lan9303_i2c *sw_dev;
+       struct lan9303_i2c *sw_dev = i2c_get_clientdata(client);
 
-       sw_dev = i2c_get_clientdata(client);
        if (!sw_dev)
-               return -ENODEV;
+               return 0;
+
+       lan9303_remove(&sw_dev->chip);
+
+       i2c_set_clientdata(client, NULL);
+
+       return 0;
+}
+
+static void lan9303_i2c_shutdown(struct i2c_client *client)
+{
+       struct lan9303_i2c *sw_dev = i2c_get_clientdata(client);
+
+       if (!sw_dev)
+               return;
+
+       lan9303_shutdown(&sw_dev->chip);
 
-       return lan9303_remove(&sw_dev->chip);
+       i2c_set_clientdata(client, NULL);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -97,6 +112,7 @@ static struct i2c_driver lan9303_i2c_driver = {
        },
        .probe = lan9303_i2c_probe,
        .remove = lan9303_i2c_remove,
+       .shutdown = lan9303_i2c_shutdown,
        .id_table = lan9303_i2c_id,
 };
 module_i2c_driver(lan9303_i2c_driver);