net: bcm63xx: Use platform_register/unregister_drivers()
authorThierry Reding <treding@nvidia.com>
Wed, 2 Dec 2015 16:30:27 +0000 (17:30 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 3 Dec 2015 20:14:58 +0000 (15:14 -0500)
These new helpers simplify implementing multi-driver modules and
properly handle failure to register one driver by unregistering all
previously registered drivers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bcm63xx_enet.c

index 8b1929e9f698c4d8da22573b483795af1bf5bc5b..a54bafad35385ce17b3ae7c38126fa57a62ee5da 100644 (file)
@@ -2884,33 +2884,21 @@ struct platform_driver bcm63xx_enet_shared_driver = {
        },
 };
 
+static struct platform_driver * const drivers[] = {
+       &bcm63xx_enet_shared_driver,
+       &bcm63xx_enet_driver,
+       &bcm63xx_enetsw_driver,
+};
+
 /* entry point */
 static int __init bcm_enet_init(void)
 {
-       int ret;
-
-       ret = platform_driver_register(&bcm63xx_enet_shared_driver);
-       if (ret)
-               return ret;
-
-       ret = platform_driver_register(&bcm63xx_enet_driver);
-       if (ret)
-               platform_driver_unregister(&bcm63xx_enet_shared_driver);
-
-       ret = platform_driver_register(&bcm63xx_enetsw_driver);
-       if (ret) {
-               platform_driver_unregister(&bcm63xx_enet_driver);
-               platform_driver_unregister(&bcm63xx_enet_shared_driver);
-       }
-
-       return ret;
+       return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
 }
 
 static void __exit bcm_enet_exit(void)
 {
-       platform_driver_unregister(&bcm63xx_enet_driver);
-       platform_driver_unregister(&bcm63xx_enetsw_driver);
-       platform_driver_unregister(&bcm63xx_enet_shared_driver);
+       platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
 }