Commit 4e12ac0f authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Greg Kroah-Hartman

[PATCH] Driver core: kset_find_obj should increment refcount of the found object

kset_find_obj should increment refcount of the found object so users of
the function can safely use returned object
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent 8f855b02
......@@ -607,6 +607,8 @@ void put_bus(struct bus_type * bus)
*
* Call kset_find_obj() to iterate over list of buses to
* find a bus by name. Return bus if found.
*
* Note that kset_find_obj increments bus' reference count.
*/
struct bus_type * find_bus(char * name)
......
......@@ -378,6 +378,16 @@ int device_for_each_child(struct device * dev, void * data,
return error;
}
/**
* device_find - locate device on a bus by name.
* @name: name of the device.
* @bus: bus to scan for the device.
*
* Call kset_find_obj() to iterate over list of devices on
* a bus to find device by name. Return device if found.
*
* Note that kset_find_obj increments device's reference count.
*/
struct device *device_find(const char *name, struct bus_type *bus)
{
struct kobject *k = kset_find_obj(&bus->devices, name);
......
......@@ -86,7 +86,14 @@ int register_vio_slot(struct device_node *dn)
}
slot->dev_type = VIO_DEV;
slot->dev.vio_dev = vio_find_node(dn);
if (!slot->dev.vio_dev)
if (slot->dev.vio_dev) {
/*
* rpaphp is the only owner of vio devices and
* does not need extra reference taken by
* vio_find_node
*/
put_device(&slot->dev.vio_dev->dev);
} else
slot->dev.vio_dev = vio_register_device_node(dn);
if (slot->dev.vio_dev)
slot->state = CONFIGURED;
......
......@@ -537,7 +537,8 @@ void kset_unregister(struct kset * k)
* @name: object's name.
*
* Lock kset via @kset->subsys, and iterate over @kset->list,
* looking for a matching kobject. Return object if found.
* looking for a matching kobject. If matching object is found
* take a reference and return the object.
*/
struct kobject * kset_find_obj(struct kset * kset, const char * name)
......@@ -548,8 +549,8 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
down_read(&kset->subsys->rwsem);
list_for_each(entry,&kset->list) {
struct kobject * k = to_kobj(entry);
if (kobject_name(k) && (!strcmp(kobject_name(k),name))) {
ret = k;
if (kobject_name(k) && !strcmp(kobject_name(k),name)) {
ret = kobject_get(k);
break;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment