Skip to content

Commit

Permalink
IB/cm: Fix infiniband_cm class kobject ref counting
Browse files Browse the repository at this point in the history
Commit 9af57b7 ("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>
  • Loading branch information
Roland Dreier committed Feb 12, 2008
1 parent ab64b96 commit 7c7a9bc
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions drivers/infiniband/core/cm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3612,18 +3612,12 @@ struct class 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)
{
int i, ret;

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);
if (ret) {
kfree(port);
Expand All @@ -3633,7 +3627,7 @@ static int cm_create_port_fs(struct cm_port *port)
for (i = 0; i < CM_COUNTER_GROUPS; i++) {
ret = kobject_init_and_add(&port->counter_group[i].obj,
&cm_counter_obj_type,
kobject_get(&port->port_obj),
&port->port_obj,
"%s", counter_group_names[i]);
if (ret)
goto error;
Expand All @@ -3643,8 +3637,8 @@ static int cm_create_port_fs(struct cm_port *port)

error:
while (i--)
cm_remove_fs_obj(&port->counter_group[i].obj);
cm_remove_fs_obj(&port->port_obj);
kobject_put(&port->counter_group[i].obj);
kobject_put(&port->port_obj);
return ret;

}
Expand All @@ -3654,9 +3648,9 @@ static void cm_remove_port_fs(struct cm_port *port)
int 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)
Expand Down Expand Up @@ -3740,7 +3734,7 @@ static void cm_add_one(struct ib_device *device)
ib_unregister_mad_agent(port->mad_agent);
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)
Expand All @@ -3767,7 +3761,7 @@ static void cm_remove_one(struct ib_device *device)
ib_unregister_mad_agent(port->mad_agent);
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)
Expand Down

0 comments on commit 7c7a9bc

Please sign in to comment.