Patchwork [4/6] Phonet: handle rtnetlink registration failure

login
register
mail settings
Submitter Rémi Denis-Courmont
Date Jan. 23, 2009, 1 p.m.
Message ID <1232715630-24951-4-git-send-email-remi.denis-courmont@nokia.com>
Download mbox | patch
Permalink /patch/20045/
State Accepted
Delegated to: David Miller
Headers show

Comments

Rémi Denis-Courmont - Jan. 23, 2009, 1 p.m.
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/pn_dev.h |    2 +-
 net/phonet/pn_dev.c         |    8 ++++++--
 net/phonet/pn_netlink.c     |   13 +++++++++----
 3 files changed, 16 insertions(+), 7 deletions(-)

Patch

diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index 59ae628..4ba2aed 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -38,7 +38,7 @@  struct phonet_device {
 
 int phonet_device_init(void);
 void phonet_device_exit(void);
-void phonet_netlink_register(void);
+int phonet_netlink_register(void);
 struct net_device *phonet_device_get(struct net *net);
 
 int phonet_address_add(struct net_device *dev, u8 addr);
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index af49db0..fd41810 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -190,9 +190,13 @@  static struct notifier_block phonet_device_notifier = {
 /* Initialize Phonet devices list */
 int __init phonet_device_init(void)
 {
+	int err;
+
 	register_netdevice_notifier(&phonet_device_notifier);
-	phonet_netlink_register();
-	return 0;
+	err = phonet_netlink_register();
+	if (err)
+		phonet_device_exit();
+	return err;
 }
 
 void phonet_device_exit(void)
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index 242fe8f..918a4f0 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -160,9 +160,14 @@  out:
 	return skb->len;
 }
 
-void __init phonet_netlink_register(void)
+int __init phonet_netlink_register(void)
 {
-	rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL);
-	rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL);
-	rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit);
+	int err = __rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL);
+	if (err)
+		return err;
+
+	/* Further __rtnl_register() cannot fail */
+	__rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL);
+	__rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit);
+	return 0;
 }