[v2,05/26] batman-adv: init, Add some error handling

Message ID 1419594103-10928-6-git-send-email-mpa@pengutronix.de (mailing list archive)
State Changes Requested
Headers

Commit Message

Markus Pargmann Dec. 26, 2014, 11:41 a.m. UTC
  This patch adds some error handling for the main init function. It
checks the return values of all the function calls that provide return
values.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
 main.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
  

Comments

Marek Lindner Jan. 11, 2015, 12:38 p.m. UTC | #1
On Friday 26 December 2014 12:41:22 Markus Pargmann wrote:
>  static int __init batadv_init(void)
>  {
> +       int ret;
> +
>         INIT_LIST_HEAD(&batadv_hardif_list);
>         INIT_HLIST_HEAD(&batadv_algo_list);
>  
>         batadv_recv_handler_init();
>  
> -       batadv_iv_init();
> -       batadv_nc_init();
> +       ret = batadv_iv_init();
> +       if (ret)
> +               return ret;
> +
> +       ret = batadv_nc_init();
> +       if (ret)
> +               return ret;
>  
>         batadv_event_workqueue =
> create_singlethread_workqueue("bat_events"); -
>         if (!batadv_event_workqueue)
>                 return -ENOMEM;
>  
>         batadv_socket_init();
>         batadv_debugfs_init();
>  
> -       register_netdevice_notifier(&batadv_hard_if_notifier);
> -       rtnl_link_register(&batadv_link_ops);
> +       ret = register_netdevice_notifier(&batadv_hard_if_notifier);
> +       if (ret)
> +               goto err_netdev_notifier;
> +
> +       ret = rtnl_link_register(&batadv_link_ops);
> +       if (ret)
> +               goto err_link_register;
>  
>         pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i)
> loaded\n", BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);
>  
>         return 0;
> +
> +err_link_register:
> +       unregister_netdevice_notifier(&batadv_hard_if_notifier);
> +err_netdev_notifier:
> +       batadv_debugfs_destroy();
> +
> +       return ret;
>  }

To be truely clean, I guess the workqueue should be destroyed as well ?

Cheers,
Marek
  
Markus Pargmann Jan. 14, 2015, 3:24 p.m. UTC | #2
On Sun, Jan 11, 2015 at 08:38:10PM +0800, Marek Lindner wrote:
> On Friday 26 December 2014 12:41:22 Markus Pargmann wrote:
> >  static int __init batadv_init(void)
> >  {
> > +       int ret;
> > +
> >         INIT_LIST_HEAD(&batadv_hardif_list);
> >         INIT_HLIST_HEAD(&batadv_algo_list);
> >  
> >         batadv_recv_handler_init();
> >  
> > -       batadv_iv_init();
> > -       batadv_nc_init();
> > +       ret = batadv_iv_init();
> > +       if (ret)
> > +               return ret;
> > +
> > +       ret = batadv_nc_init();
> > +       if (ret)
> > +               return ret;
> >  
> >         batadv_event_workqueue =
> > create_singlethread_workqueue("bat_events"); -
> >         if (!batadv_event_workqueue)
> >                 return -ENOMEM;
> >  
> >         batadv_socket_init();
> >         batadv_debugfs_init();
> >  
> > -       register_netdevice_notifier(&batadv_hard_if_notifier);
> > -       rtnl_link_register(&batadv_link_ops);
> > +       ret = register_netdevice_notifier(&batadv_hard_if_notifier);
> > +       if (ret)
> > +               goto err_netdev_notifier;
> > +
> > +       ret = rtnl_link_register(&batadv_link_ops);
> > +       if (ret)
> > +               goto err_link_register;
> >  
> >         pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i)
> > loaded\n", BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);
> >  
> >         return 0;
> > +
> > +err_link_register:
> > +       unregister_netdevice_notifier(&batadv_hard_if_notifier);
> > +err_netdev_notifier:
> > +       batadv_debugfs_destroy();
> > +
> > +       return ret;
> >  }
> 
> To be truely clean, I guess the workqueue should be destroyed as well ?

Yes, thanks, added destroy_workqueue() for v3.

Best Regards,

Markus
  

Patch

diff --git a/main.c b/main.c
index a9e09e852c4b..65021ea567e8 100644
--- a/main.c
+++ b/main.c
@@ -59,29 +59,47 @@  static void batadv_recv_handler_init(void);
 
 static int __init batadv_init(void)
 {
+	int ret;
+
 	INIT_LIST_HEAD(&batadv_hardif_list);
 	INIT_HLIST_HEAD(&batadv_algo_list);
 
 	batadv_recv_handler_init();
 
-	batadv_iv_init();
-	batadv_nc_init();
+	ret = batadv_iv_init();
+	if (ret)
+		return ret;
+
+	ret = batadv_nc_init();
+	if (ret)
+		return ret;
 
 	batadv_event_workqueue = create_singlethread_workqueue("bat_events");
-
 	if (!batadv_event_workqueue)
 		return -ENOMEM;
 
 	batadv_socket_init();
 	batadv_debugfs_init();
 
-	register_netdevice_notifier(&batadv_hard_if_notifier);
-	rtnl_link_register(&batadv_link_ops);
+	ret = register_netdevice_notifier(&batadv_hard_if_notifier);
+	if (ret)
+		goto err_netdev_notifier;
+
+	ret = rtnl_link_register(&batadv_link_ops);
+	if (ret)
+		goto err_link_register;
 
 	pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
 		BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);
 
 	return 0;
+
+err_link_register:
+	unregister_netdevice_notifier(&batadv_hard_if_notifier);
+err_netdev_notifier:
+	batadv_debugfs_destroy();
+
+	return ret;
 }
 
 static void __exit batadv_exit(void)