Skip to content

Commit 7cd9c9b

Browse files
committed
Revert "driver core: check start node in klist_iter_init_node"
This reverts commit a15d49f as that patch broke the build. Cc: Hannes Reinecke <hare@suse.de> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 591bfc6 commit 7cd9c9b

6 files changed

Lines changed: 46 additions & 76 deletions

File tree

‎drivers/base/bus.c‎

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,11 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
296296
if (!bus)
297297
return -EINVAL;
298298

299-
error = klist_iter_init_node(&bus->p->klist_devices, &i,
300-
(start ? &start->p->knode_bus : NULL));
301-
if (!error) {
302-
while ((dev = next_device(&i)) && !error)
303-
error = fn(dev, data);
304-
klist_iter_exit(&i);
305-
}
299+
klist_iter_init_node(&bus->p->klist_devices, &i,
300+
(start ? &start->p->knode_bus : NULL));
301+
while ((dev = next_device(&i)) && !error)
302+
error = fn(dev, data);
303+
klist_iter_exit(&i);
306304
return error;
307305
}
308306
EXPORT_SYMBOL_GPL(bus_for_each_dev);
@@ -332,10 +330,8 @@ struct device *bus_find_device(struct bus_type *bus,
332330
if (!bus)
333331
return NULL;
334332

335-
if (klist_iter_init_node(&bus->p->klist_devices, &i,
336-
(start ? &start->p->knode_bus : NULL)) < 0)
337-
return NULL;
338-
333+
klist_iter_init_node(&bus->p->klist_devices, &i,
334+
(start ? &start->p->knode_bus : NULL));
339335
while ((dev = next_device(&i)))
340336
if (match(dev, data) && get_device(dev))
341337
break;
@@ -388,9 +384,7 @@ struct device *subsys_find_device_by_id(struct bus_type *subsys, unsigned int id
388384
return NULL;
389385

390386
if (hint) {
391-
if (klist_iter_init_node(&subsys->p->klist_devices, &i,
392-
&hint->p->knode_bus) < 0)
393-
return NULL;
387+
klist_iter_init_node(&subsys->p->klist_devices, &i, &hint->p->knode_bus);
394388
dev = next_device(&i);
395389
if (dev && dev->id == id && get_device(dev)) {
396390
klist_iter_exit(&i);
@@ -452,13 +446,11 @@ int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
452446
if (!bus)
453447
return -EINVAL;
454448

455-
error = klist_iter_init_node(&bus->p->klist_drivers, &i,
456-
start ? &start->p->knode_bus : NULL);
457-
if (!error) {
458-
while ((drv = next_driver(&i)) && !error)
459-
error = fn(drv, data);
460-
klist_iter_exit(&i);
461-
}
449+
klist_iter_init_node(&bus->p->klist_drivers, &i,
450+
start ? &start->p->knode_bus : NULL);
451+
while ((drv = next_driver(&i)) && !error)
452+
error = fn(drv, data);
453+
klist_iter_exit(&i);
462454
return error;
463455
}
464456
EXPORT_SYMBOL_GPL(bus_for_each_drv);
@@ -1119,19 +1111,15 @@ EXPORT_SYMBOL_GPL(bus_sort_breadthfirst);
11191111
* otherwise if it is NULL, the iteration starts at the beginning of
11201112
* the list.
11211113
*/
1122-
int subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys,
1123-
struct device *start, const struct device_type *type)
1114+
void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys,
1115+
struct device *start, const struct device_type *type)
11241116
{
11251117
struct klist_node *start_knode = NULL;
1126-
int error;
11271118

11281119
if (start)
11291120
start_knode = &start->p->knode_bus;
1130-
error = klist_iter_init_node(&subsys->p->klist_devices, &iter->ki,
1131-
start_knode);
1132-
if (!error)
1133-
iter->type = type;
1134-
return error;
1121+
klist_iter_init_node(&subsys->p->klist_devices, &iter->ki, start_knode);
1122+
iter->type = type;
11351123
}
11361124
EXPORT_SYMBOL_GPL(subsys_dev_iter_init);
11371125

‎drivers/base/class.c‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,15 @@ void class_destroy(struct class *cls)
301301
* otherwise if it is NULL, the iteration starts at the beginning of
302302
* the list.
303303
*/
304-
int class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
305-
struct device *start, const struct device_type *type)
304+
void class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
305+
struct device *start, const struct device_type *type)
306306
{
307307
struct klist_node *start_knode = NULL;
308-
int error;
309308

310309
if (start)
311310
start_knode = &start->knode_class;
312-
error = klist_iter_init_node(&class->p->klist_devices, &iter->ki,
313-
start_knode);
314-
if (!error)
315-
iter->type = type;
316-
317-
return error;
311+
klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode);
312+
iter->type = type;
318313
}
319314
EXPORT_SYMBOL_GPL(class_dev_iter_init);
320315

@@ -392,15 +387,14 @@ int class_for_each_device(struct class *class, struct device *start,
392387
return -EINVAL;
393388
}
394389

395-
error = class_dev_iter_init(&iter, class, start, NULL);
396-
if (!error) {
397-
while ((dev = class_dev_iter_next(&iter))) {
398-
error = fn(dev, data);
399-
if (error)
400-
break;
401-
}
402-
class_dev_iter_exit(&iter);
390+
class_dev_iter_init(&iter, class, start, NULL);
391+
while ((dev = class_dev_iter_next(&iter))) {
392+
error = fn(dev, data);
393+
if (error)
394+
break;
403395
}
396+
class_dev_iter_exit(&iter);
397+
404398
return error;
405399
}
406400
EXPORT_SYMBOL_GPL(class_for_each_device);
@@ -440,9 +434,7 @@ struct device *class_find_device(struct class *class, struct device *start,
440434
return NULL;
441435
}
442436

443-
if (class_dev_iter_init(&iter, class, start, NULL) < 0)
444-
return NULL;
445-
437+
class_dev_iter_init(&iter, class, start, NULL);
446438
while ((dev = class_dev_iter_next(&iter))) {
447439
if (match(dev, data)) {
448440
get_device(dev);

‎drivers/base/driver.c‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
4949
if (!drv)
5050
return -EINVAL;
5151

52-
error = klist_iter_init_node(&drv->p->klist_devices, &i,
53-
start ? &start->p->knode_driver : NULL);
54-
if (!error) {
55-
while ((dev = next_device(&i)) && !error)
56-
error = fn(dev, data);
57-
klist_iter_exit(&i);
58-
}
52+
klist_iter_init_node(&drv->p->klist_devices, &i,
53+
start ? &start->p->knode_driver : NULL);
54+
while ((dev = next_device(&i)) && !error)
55+
error = fn(dev, data);
56+
klist_iter_exit(&i);
5957
return error;
6058
}
6159
EXPORT_SYMBOL_GPL(driver_for_each_device);
@@ -85,10 +83,8 @@ struct device *driver_find_device(struct device_driver *drv,
8583
if (!drv)
8684
return NULL;
8785

88-
if (klist_iter_init_node(&drv->p->klist_devices, &i,
89-
(start ? &start->p->knode_driver : NULL)) < 0)
90-
return NULL;
91-
86+
klist_iter_init_node(&drv->p->klist_devices, &i,
87+
(start ? &start->p->knode_driver : NULL));
9288
while ((dev = next_device(&i)))
9389
if (match(dev, data) && get_device(dev))
9490
break;

‎include/linux/device.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct subsys_dev_iter {
128128
struct klist_iter ki;
129129
const struct device_type *type;
130130
};
131-
int subsys_dev_iter_init(struct subsys_dev_iter *iter,
131+
void subsys_dev_iter_init(struct subsys_dev_iter *iter,
132132
struct bus_type *subsys,
133133
struct device *start,
134134
const struct device_type *type);
@@ -380,10 +380,10 @@ int class_compat_create_link(struct class_compat *cls, struct device *dev,
380380
void class_compat_remove_link(struct class_compat *cls, struct device *dev,
381381
struct device *device_link);
382382

383-
extern int class_dev_iter_init(struct class_dev_iter *iter,
384-
struct class *class,
385-
struct device *start,
386-
const struct device_type *type);
383+
extern void class_dev_iter_init(struct class_dev_iter *iter,
384+
struct class *class,
385+
struct device *start,
386+
const struct device_type *type);
387387
extern struct device *class_dev_iter_next(struct class_dev_iter *iter);
388388
extern void class_dev_iter_exit(struct class_dev_iter *iter);
389389

‎include/linux/klist.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct klist_iter {
6060

6161

6262
extern void klist_iter_init(struct klist *k, struct klist_iter *i);
63-
extern int klist_iter_init_node(struct klist *k, struct klist_iter *i,
63+
extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
6464
struct klist_node *n);
6565
extern void klist_iter_exit(struct klist_iter *i);
6666
extern struct klist_node *klist_next(struct klist_iter *i);

‎lib/klist.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,19 +278,13 @@ EXPORT_SYMBOL_GPL(klist_node_attached);
278278
* Similar to klist_iter_init(), but starts the action off with @n,
279279
* instead of with the list head.
280280
*/
281-
int klist_iter_init_node(struct klist *k, struct klist_iter *i,
282-
struct klist_node *n)
281+
void klist_iter_init_node(struct klist *k, struct klist_iter *i,
282+
struct klist_node *n)
283283
{
284-
if (n) {
285-
kref_get(&n->n_ref);
286-
if (!n->n_klist) {
287-
kref_put(&n->n_ref);
288-
return -ENODEV;
289-
}
290-
}
291284
i->i_klist = k;
292285
i->i_cur = n;
293-
return 0;
286+
if (n)
287+
kref_get(&n->n_ref);
294288
}
295289
EXPORT_SYMBOL_GPL(klist_iter_init_node);
296290

0 commit comments

Comments
 (0)