@@ -1460,19 +1460,57 @@ static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
1460
1460
slave -> dev -> flags &= ~IFF_SLAVE ;
1461
1461
}
1462
1462
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 )
1464
1496
{
1465
1497
struct slave * slave = NULL ;
1466
1498
1467
1499
slave = kzalloc (sizeof (* slave ), GFP_KERNEL );
1468
1500
if (!slave )
1469
1501
return NULL ;
1470
1502
1503
+ slave -> bond = bond ;
1504
+ slave -> dev = slave_dev ;
1505
+
1506
+ if (bond_kobj_init (slave ))
1507
+ return NULL ;
1508
+
1471
1509
if (BOND_MODE (bond ) == BOND_MODE_8023AD ) {
1472
1510
SLAVE_AD_INFO (slave ) = kzalloc (sizeof (struct ad_slave_info ),
1473
1511
GFP_KERNEL );
1474
1512
if (!SLAVE_AD_INFO (slave )) {
1475
- kfree ( slave );
1513
+ kobject_put ( & slave -> kobj );
1476
1514
return NULL ;
1477
1515
}
1478
1516
}
@@ -1481,17 +1519,6 @@ static struct slave *bond_alloc_slave(struct bonding *bond)
1481
1519
return slave ;
1482
1520
}
1483
1521
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
-
1495
1522
static void bond_fill_ifbond (struct bonding * bond , struct ifbond * info )
1496
1523
{
1497
1524
info -> bond_mode = BOND_MODE (bond );
@@ -1678,14 +1705,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
1678
1705
goto err_undo_flags ;
1679
1706
}
1680
1707
1681
- new_slave = bond_alloc_slave (bond );
1708
+ new_slave = bond_alloc_slave (bond , slave_dev );
1682
1709
if (!new_slave ) {
1683
1710
res = - ENOMEM ;
1684
1711
goto err_undo_flags ;
1685
1712
}
1686
1713
1687
- new_slave -> bond = bond ;
1688
- new_slave -> dev = slave_dev ;
1689
1714
/* Set the new_slave's queue_id to be zero. Queue ID mapping
1690
1715
* is set via sysfs or module option if desired.
1691
1716
*/
@@ -2007,7 +2032,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
2007
2032
dev_set_mtu (slave_dev , new_slave -> original_mtu );
2008
2033
2009
2034
err_free :
2010
- bond_free_slave ( new_slave );
2035
+ kobject_put ( & new_slave -> kobj );
2011
2036
2012
2037
err_undo_flags :
2013
2038
/* 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,
2187
2212
if (!netif_is_bond_master (slave_dev ))
2188
2213
slave_dev -> priv_flags &= ~IFF_BONDING ;
2189
2214
2190
- bond_free_slave ( slave );
2215
+ kobject_put ( & slave -> kobj );
2191
2216
2192
2217
return 0 ;
2193
2218
}
0 commit comments