IB/cm: Fix infiniband_cm class kobject ref counting

Commit 9af57b7a ("IB/cm: Add basic performance counters") introduced a
bug in how the reference count for cm_class.subsys.kobj was handled:
the path that released a device did a kobject_put() on that kobject, but
there was no kobject_get() in the path the handles adding a device.  So
the reference count ended up too low, which leads to bad things.  Fix up
and simplify the reference counting to avoid this.

(Actually, I introduced the bug when fixing the patch up to match some
of Greg's kobject changes, but who's counting)

Signed-off-by: Roland Dreier <rolandd@cisco.com>
This commit is contained in:
Roland Dreier 2008-02-12 14:38:27 -08:00
parent ab64b96067
commit 7c7a9bccd2
1 changed files with 8 additions and 14 deletions

View File

@ -3612,18 +3612,12 @@ struct class cm_class = {
}; };
EXPORT_SYMBOL(cm_class); EXPORT_SYMBOL(cm_class);
static void cm_remove_fs_obj(struct kobject *obj)
{
kobject_put(obj->parent);
kobject_put(obj);
}
static int cm_create_port_fs(struct cm_port *port) static int cm_create_port_fs(struct cm_port *port)
{ {
int i, ret; int i, ret;
ret = kobject_init_and_add(&port->port_obj, &cm_port_obj_type, ret = kobject_init_and_add(&port->port_obj, &cm_port_obj_type,
kobject_get(&port->cm_dev->dev_obj), &port->cm_dev->dev_obj,
"%d", port->port_num); "%d", port->port_num);
if (ret) { if (ret) {
kfree(port); kfree(port);
@ -3633,7 +3627,7 @@ static int cm_create_port_fs(struct cm_port *port)
for (i = 0; i < CM_COUNTER_GROUPS; i++) { for (i = 0; i < CM_COUNTER_GROUPS; i++) {
ret = kobject_init_and_add(&port->counter_group[i].obj, ret = kobject_init_and_add(&port->counter_group[i].obj,
&cm_counter_obj_type, &cm_counter_obj_type,
kobject_get(&port->port_obj), &port->port_obj,
"%s", counter_group_names[i]); "%s", counter_group_names[i]);
if (ret) if (ret)
goto error; goto error;
@ -3643,8 +3637,8 @@ static int cm_create_port_fs(struct cm_port *port)
error: error:
while (i--) while (i--)
cm_remove_fs_obj(&port->counter_group[i].obj); kobject_put(&port->counter_group[i].obj);
cm_remove_fs_obj(&port->port_obj); kobject_put(&port->port_obj);
return ret; return ret;
} }
@ -3654,9 +3648,9 @@ static void cm_remove_port_fs(struct cm_port *port)
int i; int i;
for (i = 0; i < CM_COUNTER_GROUPS; i++) for (i = 0; i < CM_COUNTER_GROUPS; i++)
cm_remove_fs_obj(&port->counter_group[i].obj); kobject_put(&port->counter_group[i].obj);
cm_remove_fs_obj(&port->port_obj); kobject_put(&port->port_obj);
} }
static void cm_add_one(struct ib_device *device) static void cm_add_one(struct ib_device *device)
@ -3740,7 +3734,7 @@ error1:
ib_unregister_mad_agent(port->mad_agent); ib_unregister_mad_agent(port->mad_agent);
cm_remove_port_fs(port); cm_remove_port_fs(port);
} }
cm_remove_fs_obj(&cm_dev->dev_obj); kobject_put(&cm_dev->dev_obj);
} }
static void cm_remove_one(struct ib_device *device) static void cm_remove_one(struct ib_device *device)
@ -3767,7 +3761,7 @@ static void cm_remove_one(struct ib_device *device)
ib_unregister_mad_agent(port->mad_agent); ib_unregister_mad_agent(port->mad_agent);
cm_remove_port_fs(port); cm_remove_port_fs(port);
} }
cm_remove_fs_obj(&cm_dev->dev_obj); kobject_put(&cm_dev->dev_obj);
} }
static int __init ib_cm_init(void) static int __init ib_cm_init(void)