Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bonding: Fix reference count leak in bond_sysfs_slave_add.

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object. Previous
commit "b8eb718348b8" fixed a similar problem.

Fixes: 07699f9a7c8d ("bonding: add sysfs /slave dir for bond slave devices.")
Signed-off-by: Qiushi Wu <wu000273@umn.edu>
Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Qiushi Wu and committed by
David S. Miller
a068aab4 2200313a

+3 -1
+3 -1
drivers/net/bonding/bond_sysfs_slave.c
··· 149 149 150 150 err = kobject_init_and_add(&slave->kobj, &slave_ktype, 151 151 &(slave->dev->dev.kobj), "bonding_slave"); 152 - if (err) 152 + if (err) { 153 + kobject_put(&slave->kobj); 153 154 return err; 155 + } 154 156 155 157 for (a = slave_attrs; *a; ++a) { 156 158 err = sysfs_create_file(&slave->kobj, &((*a)->attr));