net: mpc52xx: Use platform_register/unregister_drivers()
authorThierry Reding <treding@nvidia.com>
Wed, 2 Dec 2015 16:30:28 +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/freescale/fec_mpc52xx.c

index afe7f39cdd7cc2f5c7a7e1833090810b2400f2ba..25553ee857b4671e08904a015dd8daf854b9a90d 100644 (file)
@@ -1084,27 +1084,23 @@ static struct platform_driver mpc52xx_fec_driver = {
 /* Module                                                                   */
 /* ======================================================================== */
 
+static struct platform_driver * const drivers[] = {
+#ifdef CONFIG_FEC_MPC52xx_MDIO
+       &mpc52xx_fec_mdio_driver,
+#endif
+       &mpc52xx_fec_driver,
+};
+
 static int __init
 mpc52xx_fec_init(void)
 {
-#ifdef CONFIG_FEC_MPC52xx_MDIO
-       int ret;
-       ret = platform_driver_register(&mpc52xx_fec_mdio_driver);
-       if (ret) {
-               pr_err("failed to register mdio driver\n");
-               return ret;
-       }
-#endif
-       return platform_driver_register(&mpc52xx_fec_driver);
+       return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
 }
 
 static void __exit
 mpc52xx_fec_exit(void)
 {
-       platform_driver_unregister(&mpc52xx_fec_driver);
-#ifdef CONFIG_FEC_MPC52xx_MDIO
-       platform_driver_unregister(&mpc52xx_fec_mdio_driver);
-#endif
+       platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
 }