Skip to contentSkip to conversation

bonding: fix device leak on error in bond_create()

PATCH Patrick McHardy 3 participants 5 messages Feb 26, 2010 – Feb 27, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

commit f357a5caa0ca29b74811a0fc08efb5ae4aade959

Author: Patrick McHardy <[email protected]>
Date:   Thu Feb 25 20:21:10 2010 +0100

bonding: fix device leak on error in bond_create()

When the register_netdevice() call fails, the newly allocated device is not freed.

drivers/net/bonding/bond_main.c +2 -0
index 1787e3c..430c022 100644
@@ -4946,6 +4946,8 @@ int bond_create(struct net *net, const char *name)
 	}
 
 	res = register_netdevice(bond_dev);
+	if (res < 0)
+		goto out_netdev;
 
 out:
 	rtnl_unlock();
#1 lore raw
Quoted 16 lines · Patrick McHardy

commit f357a5caa0ca29b74811a0fc08efb5ae4aade959

Author: Patrick McHardy <[email protected]>
Date:   Thu Feb 25 20:21:10 2010 +0100

bonding: fix device leak on error in bond_create()

When the register_netdevice() call fails, the newly allocated device is not freed.

drivers/net/bonding/bond_main.c +0 -0
index 1787e3c..430c022 100644

drivers/net/bonding/bond_main.c int bond_create(struct net *net, const char *name) · line 4953

Quoted 8 lines
drivers/net/bonding/bond_main.c +2 -0
@@ -4946,6 +4946,8 @@ int bond_create(struct net *net, const char *name)
 	}
 
 	res = register_netdevice(bond_dev);
+	if (res < 0)
+		goto out_netdev;
 
 out:
 	rtnl_unlock();

Seems like a good idea. I know register_netdevice is always supposed to return a value < 0 on error, but this would work if it didn't for some reason.

drivers/net/bonding/bond_main.c +2 -0
index 1787e3c..cd3ea54 100644
@@ -4946,6 +4946,8 @@ int bond_create(struct net *net, const char *name)
 	}
 
 	res = register_netdevice(bond_dev);
+	if (res)
+		goto out_netdev;
 
 out:
 	rtnl_unlock();
#2 lore raw
Quoted 24 lines · Andy Gospodarek
Quoted 22 lines · Patrick McHardy

commit f357a5caa0ca29b74811a0fc08efb5ae4aade959

Author: Patrick McHardy <[email protected]>
Date:   Thu Feb 25 20:21:10 2010 +0100

bonding: fix device leak on error in bond_create()

When the register_netdevice() call fails, the newly allocated device is not freed.

drivers/net/bonding/bond_main.c +2 -0
index 1787e3c..430c022 100644
@@ -4946,6 +4946,8 @@ int bond_create(struct net *net, const char *name)
 	}
 
 	res = register_netdevice(bond_dev);
+	if (res < 0)
+		goto out_netdev;
 
Quoted 8 lines

drivers/net/bonding/bond_main.c int bond_create(struct net *net, const char *name) · line 4953

Quoted 2 lines
drivers/net/bonding/bond_main.c +0 -0
 out:
 	rtnl_unlock();

Seems like a good idea. I know register_netdevice is always supposed to return a value < 0 on error, but this would work if it didn't for some reason.

I don't care much, but that would be a bug since we'd return invalid errno codes to userspace.

#3 lore raw
Quoted 30 lines · Patrick McHardy
Quoted 29 lines · Andy Gospodarek
Quoted 16 lines · Patrick McHardy

commit f357a5caa0ca29b74811a0fc08efb5ae4aade959

Author: Patrick McHardy <[email protected]>
Date:   Thu Feb 25 20:21:10 2010 +0100

bonding: fix device leak on error in bond_create()

When the register_netdevice() call fails, the newly allocated device is not freed.

drivers/net/bonding/bond_main.c +0 -0
index 1787e3c..430c022 100644

drivers/net/bonding/bond_main.c int bond_create(struct net *net, const char *name) · line 4953

Quoted 8 lines
drivers/net/bonding/bond_main.c +2 -0
@@ -4946,6 +4946,8 @@ int bond_create(struct net *net, const char *name)
 	}
 
 	res = register_netdevice(bond_dev);
+	if (res < 0)
+		goto out_netdev;
 
 out:
 	rtnl_unlock();
Quoted 6 lines
Quoted 3 lines

Seems like a good idea. I know register_netdevice is always supposed to return a value < 0 on error, but this would work if it didn't for some reason.

I don't care much, but that would be a bug since we'd return invalid errno codes to userspace.

Then I guess the bonding driver would probably not be the last to know if someone snuck a bug into register_netdevice....

maintainer
#4 lore raw
In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Fri, 26 Feb 2010 16:35:52 +0100

Quoted 10 lines

commit f357a5caa0ca29b74811a0fc08efb5ae4aade959

Author: Patrick McHardy <[email protected]>
Date:   Thu Feb 25 20:21:10 2010 +0100

bonding: fix device leak on error in bond_create()

When the register_netdevice() call fails, the newly allocated device is not freed.

I think whether we should be checking for negative return values is not something to gripe over, so I've applied this, thanks!