[PATCH] Module use count must be updated as bridges are created/destroyed

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <shemminger@...>
Cc: <bridge@...>, <linux-kernel@...>
Date: Wednesday, September 26, 2007 - 3:53 am

Otherwise 'modprobe -r' on a module having a dependency on bridge will
implicitly unload bridge, bringing down all connectivity that was using
bridges.

Signed-off-by: Jan Beulich <jbeulich@novell.com>

 net/bridge/br_if.c |    9 +++++++++
 1 file changed, 9 insertions(+)

--- linux-2.6.23-rc8/net/bridge/br_if.c	2007-09-26 09:23:54.000000000 +0200
+++ 2.6.23-rc8-bridge-module-get-put/net/bridge/br_if.c	2007-09-25 14:31:01.000000000 +0200
@@ -276,6 +276,11 @@ int br_add_bridge(const char *name)
 	if (!dev)
 		return -ENOMEM;
 
+	if (!try_module_get(THIS_MODULE)) {
+		free_netdev(dev);
+		return -ENOENT;
+	}
+
 	rtnl_lock();
 	if (strchr(dev->name, '%')) {
 		ret = dev_alloc_name(dev, dev->name);
@@ -294,6 +299,8 @@ int br_add_bridge(const char *name)
 		unregister_netdevice(dev);
  out:
 	rtnl_unlock();
+	if (ret)
+		module_put(THIS_MODULE);
 	return ret;
 }
 
@@ -321,6 +328,8 @@ int br_del_bridge(const char *name)
 		del_br(netdev_priv(dev));
 
 	rtnl_unlock();
+	if (ret == 0)
+		module_put(THIS_MODULE);
 	return ret;
 }
 



-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Module use count must be updated as bridges are crea..., Jan Beulich, (Wed Sep 26, 3:53 am)
Re: [PATCH] Module use count must be updated as bridges are ..., Stephen Hemminger, (Wed Sep 26, 11:37 am)
Re: why network devices don't do reference counting? (Re: [P..., Stephen Hemminger, (Wed Sep 26, 5:06 pm)
Re: why network devices don't do reference counting? (Re: [P..., Stephen Hemminger, (Wed Sep 26, 6:33 pm)
Re: why network devices don't do reference counting?, David Miller, (Thu Sep 27, 3:01 pm)
Re: why network devices don't do reference counting? (Re: [P..., Stephen Hemminger, (Thu Sep 27, 10:51 am)
Re: why network devices don't do reference counting?, David Miller, (Thu Sep 27, 3:15 pm)
Re: why network devices don't do reference counting?, David Miller, (Wed Sep 26, 6:57 pm)