@@ -1460,19 +1460,57 @@ static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
14601460	slave -> dev -> flags  &= ~IFF_SLAVE ;
14611461}
14621462
1463- static  struct  slave  * bond_alloc_slave (struct  bonding  * bond )
1463+ static  void  slave_kobj_release (struct  kobject  * kobj )
1464+ {
1465+ 	struct  slave  * slave  =  to_slave (kobj );
1466+ 	struct  bonding  * bond  =  bond_get_bond_by_slave (slave );
1467+ 
1468+ 	cancel_delayed_work_sync (& slave -> notify_work );
1469+ 	if  (BOND_MODE (bond ) ==  BOND_MODE_8023AD )
1470+ 		kfree (SLAVE_AD_INFO (slave ));
1471+ 
1472+ 	kfree (slave );
1473+ }
1474+ 
1475+ static  struct  kobj_type  slave_ktype  =  {
1476+ 	.release  =  slave_kobj_release ,
1477+ #ifdef  CONFIG_SYSFS 
1478+ 	.sysfs_ops  =  & slave_sysfs_ops ,
1479+ #endif 
1480+ };
1481+ 
1482+ static  int  bond_kobj_init (struct  slave  * slave )
1483+ {
1484+ 	int  err ;
1485+ 
1486+ 	err  =  kobject_init_and_add (& slave -> kobj , & slave_ktype ,
1487+ 				   & (slave -> dev -> dev .kobj ), "bonding_slave" );
1488+ 	if  (err )
1489+ 		kobject_put (& slave -> kobj );
1490+ 
1491+ 	return  err ;
1492+ }
1493+ 
1494+ static  struct  slave  * bond_alloc_slave (struct  bonding  * bond ,
1495+ 				      struct  net_device  * slave_dev )
14641496{
14651497	struct  slave  * slave  =  NULL ;
14661498
14671499	slave  =  kzalloc (sizeof (* slave ), GFP_KERNEL );
14681500	if  (!slave )
14691501		return  NULL ;
14701502
1503+ 	slave -> bond  =  bond ;
1504+ 	slave -> dev  =  slave_dev ;
1505+ 
1506+ 	if  (bond_kobj_init (slave ))
1507+ 		return  NULL ;
1508+ 
14711509	if  (BOND_MODE (bond ) ==  BOND_MODE_8023AD ) {
14721510		SLAVE_AD_INFO (slave ) =  kzalloc (sizeof (struct  ad_slave_info ),
14731511					       GFP_KERNEL );
14741512		if  (!SLAVE_AD_INFO (slave )) {
1475- 			kfree ( slave );
1513+ 			kobject_put ( & slave -> kobj );
14761514			return  NULL ;
14771515		}
14781516	}
@@ -1481,17 +1519,6 @@ static struct slave *bond_alloc_slave(struct bonding *bond)
14811519	return  slave ;
14821520}
14831521
1484- static  void  bond_free_slave (struct  slave  * slave )
1485- {
1486- 	struct  bonding  * bond  =  bond_get_bond_by_slave (slave );
1487- 
1488- 	cancel_delayed_work_sync (& slave -> notify_work );
1489- 	if  (BOND_MODE (bond ) ==  BOND_MODE_8023AD )
1490- 		kfree (SLAVE_AD_INFO (slave ));
1491- 
1492- 	kfree (slave );
1493- }
1494- 
14951522static  void  bond_fill_ifbond (struct  bonding  * bond , struct  ifbond  * info )
14961523{
14971524	info -> bond_mode  =  BOND_MODE (bond );
@@ -1678,14 +1705,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
16781705			goto err_undo_flags ;
16791706	}
16801707
1681- 	new_slave  =  bond_alloc_slave (bond );
1708+ 	new_slave  =  bond_alloc_slave (bond ,  slave_dev );
16821709	if  (!new_slave ) {
16831710		res  =  - ENOMEM ;
16841711		goto err_undo_flags ;
16851712	}
16861713
1687- 	new_slave -> bond  =  bond ;
1688- 	new_slave -> dev  =  slave_dev ;
16891714	/* Set the new_slave's queue_id to be zero.  Queue ID mapping 
16901715	 * is set via sysfs or module option if desired. 
16911716	 */ 
@@ -2007,7 +2032,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
20072032	dev_set_mtu (slave_dev , new_slave -> original_mtu );
20082033
20092034err_free :
2010- 	bond_free_slave ( new_slave );
2035+ 	kobject_put ( & new_slave -> kobj );
20112036
20122037err_undo_flags :
20132038	/* Enslave of first slave has failed and we need to fix master's mac */ 
@@ -2187,7 +2212,7 @@ static int __bond_release_one(struct net_device *bond_dev,
21872212	if  (!netif_is_bond_master (slave_dev ))
21882213		slave_dev -> priv_flags  &= ~IFF_BONDING ;
21892214
2190- 	bond_free_slave ( slave );
2215+ 	kobject_put ( & slave -> kobj );
21912216
21922217	return  0 ;
21932218}
0 commit comments