Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304034
b: refs/heads/master
c: a15d49f
h: refs/heads/master
v: v3
  • Loading branch information
Hannes Reinecke authored and Greg Kroah-Hartman committed Apr 18, 2012
1 parent c7fd4c2 commit ff84357
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 47 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 97ec448aeadff55234368a89c4a07a7ef290a084
refs/heads/master: a15d49fd3094cff90e5410ca454a870e0a722fe1
46 changes: 29 additions & 17 deletions trunk/drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,13 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
if (!bus)
return -EINVAL;

klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
klist_iter_exit(&i);
error = klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
if (!error) {
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
klist_iter_exit(&i);
}
return error;
}
EXPORT_SYMBOL_GPL(bus_for_each_dev);
Expand Down Expand Up @@ -330,8 +332,10 @@ struct device *bus_find_device(struct bus_type *bus,
if (!bus)
return NULL;

klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
if (klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL)) < 0)
return NULL;

while ((dev = next_device(&i)))
if (match(dev, data) && get_device(dev))
break;
Expand Down Expand Up @@ -384,7 +388,9 @@ struct device *subsys_find_device_by_id(struct bus_type *subsys, unsigned int id
return NULL;

if (hint) {
klist_iter_init_node(&subsys->p->klist_devices, &i, &hint->p->knode_bus);
if (klist_iter_init_node(&subsys->p->klist_devices, &i,
&hint->p->knode_bus) < 0)
return NULL;
dev = next_device(&i);
if (dev && dev->id == id && get_device(dev)) {
klist_iter_exit(&i);
Expand Down Expand Up @@ -446,11 +452,13 @@ int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
if (!bus)
return -EINVAL;

klist_iter_init_node(&bus->p->klist_drivers, &i,
start ? &start->p->knode_bus : NULL);
while ((drv = next_driver(&i)) && !error)
error = fn(drv, data);
klist_iter_exit(&i);
error = klist_iter_init_node(&bus->p->klist_drivers, &i,
start ? &start->p->knode_bus : NULL);
if (!error) {
while ((drv = next_driver(&i)) && !error)
error = fn(drv, data);
klist_iter_exit(&i);
}
return error;
}
EXPORT_SYMBOL_GPL(bus_for_each_drv);
Expand Down Expand Up @@ -1111,15 +1119,19 @@ EXPORT_SYMBOL_GPL(bus_sort_breadthfirst);
* otherwise if it is NULL, the iteration starts at the beginning of
* the list.
*/
void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys,
struct device *start, const struct device_type *type)
int subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys,
struct device *start, const struct device_type *type)
{
struct klist_node *start_knode = NULL;
int error;

if (start)
start_knode = &start->p->knode_bus;
klist_iter_init_node(&subsys->p->klist_devices, &iter->ki, start_knode);
iter->type = type;
error = klist_iter_init_node(&subsys->p->klist_devices, &iter->ki,
start_knode);
if (!error)
iter->type = type;
return error;
}
EXPORT_SYMBOL_GPL(subsys_dev_iter_init);

Expand Down
32 changes: 20 additions & 12 deletions trunk/drivers/base/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,20 @@ void class_destroy(struct class *cls)
* otherwise if it is NULL, the iteration starts at the beginning of
* the list.
*/
void class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
struct device *start, const struct device_type *type)
int class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
struct device *start, const struct device_type *type)
{
struct klist_node *start_knode = NULL;
int error;

if (start)
start_knode = &start->knode_class;
klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode);
iter->type = type;
error = klist_iter_init_node(&class->p->klist_devices, &iter->ki,
start_knode);
if (!error)
iter->type = type;

return error;
}
EXPORT_SYMBOL_GPL(class_dev_iter_init);

Expand Down Expand Up @@ -387,14 +392,15 @@ int class_for_each_device(struct class *class, struct device *start,
return -EINVAL;
}

class_dev_iter_init(&iter, class, start, NULL);
while ((dev = class_dev_iter_next(&iter))) {
error = fn(dev, data);
if (error)
break;
error = class_dev_iter_init(&iter, class, start, NULL);
if (!error) {
while ((dev = class_dev_iter_next(&iter))) {
error = fn(dev, data);
if (error)
break;
}
class_dev_iter_exit(&iter);
}
class_dev_iter_exit(&iter);

return error;
}
EXPORT_SYMBOL_GPL(class_for_each_device);
Expand Down Expand Up @@ -434,7 +440,9 @@ struct device *class_find_device(struct class *class, struct device *start,
return NULL;
}

class_dev_iter_init(&iter, class, start, NULL);
if (class_dev_iter_init(&iter, class, start, NULL) < 0)
return NULL;

while ((dev = class_dev_iter_next(&iter))) {
if (match(dev, data)) {
get_device(dev);
Expand Down
18 changes: 11 additions & 7 deletions trunk/drivers/base/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
if (!drv)
return -EINVAL;

klist_iter_init_node(&drv->p->klist_devices, &i,
start ? &start->p->knode_driver : NULL);
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
klist_iter_exit(&i);
error = klist_iter_init_node(&drv->p->klist_devices, &i,
start ? &start->p->knode_driver : NULL);
if (!error) {
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
klist_iter_exit(&i);
}
return error;
}
EXPORT_SYMBOL_GPL(driver_for_each_device);
Expand Down Expand Up @@ -83,8 +85,10 @@ struct device *driver_find_device(struct device_driver *drv,
if (!drv)
return NULL;

klist_iter_init_node(&drv->p->klist_devices, &i,
(start ? &start->p->knode_driver : NULL));
if (klist_iter_init_node(&drv->p->klist_devices, &i,
(start ? &start->p->knode_driver : NULL)) < 0)
return NULL;

while ((dev = next_device(&i)))
if (match(dev, data) && get_device(dev))
break;
Expand Down
10 changes: 5 additions & 5 deletions trunk/include/linux/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct subsys_dev_iter {
struct klist_iter ki;
const struct device_type *type;
};
void subsys_dev_iter_init(struct subsys_dev_iter *iter,
int subsys_dev_iter_init(struct subsys_dev_iter *iter,
struct bus_type *subsys,
struct device *start,
const struct device_type *type);
Expand Down Expand Up @@ -380,10 +380,10 @@ int class_compat_create_link(struct class_compat *cls, struct device *dev,
void class_compat_remove_link(struct class_compat *cls, struct device *dev,
struct device *device_link);

extern void class_dev_iter_init(struct class_dev_iter *iter,
struct class *class,
struct device *start,
const struct device_type *type);
extern int class_dev_iter_init(struct class_dev_iter *iter,
struct class *class,
struct device *start,
const struct device_type *type);
extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
extern void class_dev_iter_exit(struct class_dev_iter *iter);

Expand Down
2 changes: 1 addition & 1 deletion trunk/include/linux/klist.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct klist_iter {


extern void klist_iter_init(struct klist *k, struct klist_iter *i);
extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
extern int klist_iter_init_node(struct klist *k, struct klist_iter *i,
struct klist_node *n);
extern void klist_iter_exit(struct klist_iter *i);
extern struct klist_node *klist_next(struct klist_iter *i);
Expand Down
14 changes: 10 additions & 4 deletions trunk/lib/klist.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,19 @@ EXPORT_SYMBOL_GPL(klist_node_attached);
* Similar to klist_iter_init(), but starts the action off with @n,
* instead of with the list head.
*/
void klist_iter_init_node(struct klist *k, struct klist_iter *i,
struct klist_node *n)
int klist_iter_init_node(struct klist *k, struct klist_iter *i,
struct klist_node *n)
{
if (n) {
kref_get(&n->n_ref);
if (!n->n_klist) {
kref_put(&n->n_ref);
return -ENODEV;
}
}
i->i_klist = k;
i->i_cur = n;
if (n)
kref_get(&n->n_ref);
return 0;
}
EXPORT_SYMBOL_GPL(klist_iter_init_node);

Expand Down

0 comments on commit ff84357

Please sign in to comment.