Netdev List
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: "David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, Patrick McHardy <kaber@trash.net>,
	Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH 5/6] [IPV4/IPV6]: Fail registration if inet device construction fails
Date: Thu, 26 Jul 2007 17:09:38 +0800	[thread overview]
Message-ID: <E1IDzLm-0000AP-00@gondolin.me.apana.org.au> (raw)
In-Reply-To: 20070726090725.GA510@gondor.apana.org.au

[IPV4/IPV6]: Fail registration if inet device construction fails

Now that netdev notifications can fail, we can use this to signal
errors during registration for IPv4/IPv6.  In particular, if we
fail to allocate memory for the inet device, we can fail the netdev
registration.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---

 net/ipv4/devinet.c  |    5 ++---
 net/ipv6/addrconf.c |    8 +++++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index abf6352..5b77bda 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1056,10 +1056,9 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
 	if (!in_dev) {
 		if (event == NETDEV_REGISTER) {
 			in_dev = inetdev_init(dev);
+			if (!in_dev)
+				return notifier_from_errno(-ENOMEM);
 			if (dev == &loopback_dev) {
-				if (!in_dev)
-					panic("devinet: "
-					      "Failed to create loopback\n");
 				IN_DEV_CONF_SET(in_dev, NOXFRM, 1);
 				IN_DEV_CONF_SET(in_dev, NOPOLICY, 1);
 			}
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 0601292..91ef3be 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2256,14 +2256,14 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 	struct net_device *dev = (struct net_device *) data;
 	struct inet6_dev *idev = __in6_dev_get(dev);
 	int run_pending = 0;
+	int err;
 
 	switch(event) {
 	case NETDEV_REGISTER:
 		if (!idev && dev->mtu >= IPV6_MIN_MTU) {
 			idev = ipv6_add_dev(dev);
 			if (!idev)
-				printk(KERN_WARNING "IPv6: add_dev failed for %s\n",
-					dev->name);
+				return notifier_from_errno(-ENOMEM);
 		}
 		break;
 	case NETDEV_UP:
@@ -2373,7 +2373,9 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 					      NULL);
 			addrconf_sysctl_register(idev, &idev->cnf);
 #endif
-			snmp6_register_dev(idev);
+			err = snmp6_register_dev(idev);
+			if (err)
+				return notifier_from_errno(err);
 		}
 		break;
 	}

  parent reply	other threads:[~2007-07-26  9:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-26  9:07 [0/6] Allow registration/change name notifications to fail Herbert Xu
2007-07-26  9:09 ` [PATCH 1/6] [NET]: Call uninit if necessary in register_netdevice Herbert Xu
2007-07-30 23:29   ` David Miller
2007-07-26  9:09 ` [PATCH 2/6] [NET]: Take dev_base_lock when moving device name hash list entry Herbert Xu
2007-07-30 23:36   ` David Miller
2007-07-26  9:09 ` [PATCH 3/6] [NET] loopback: Panic if registration fails Herbert Xu
2007-07-30 23:38   ` David Miller
2007-07-26  9:09 ` [PATCH 4/6] [NET]: Allow netdev REGISTER/CHANGENAME events to fail Herbert Xu
2007-07-31  0:03   ` David Miller
2007-07-26  9:09 ` Herbert Xu [this message]
2007-07-31  0:05   ` [PATCH 5/6] [IPV4/IPV6]: Fail registration if inet device construction fails David Miller
2007-07-26  9:09 ` [PATCH 6/6] [IPV6]: Remove circular dependency on if_inet6.h Herbert Xu
2007-07-31  0:06   ` David Miller
2007-07-26 10:37 ` [0/6] Allow registration/change name notifications to fail Stephen Hemminger
2007-07-26 11:03   ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1IDzLm-0000AP-00@gondolin.me.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox