Skip to content

Commit 83b9148

Browse files
committed
driver core: bus: bus iterator cleanups
Convert the bus_for_each_dev(), bus_find_device, and bus_for_each_drv() functions to use bus_to_subsys() and not use the back-pointer to the private structure. Cc: "Rafael J. Wysocki" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e4f0568 commit 83b9148

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/base/bus.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,20 @@ static struct device *next_device(struct klist_iter *i)
355355
int bus_for_each_dev(const struct bus_type *bus, struct device *start,
356356
void *data, int (*fn)(struct device *, void *))
357357
{
358+
struct subsys_private *sp = bus_to_subsys(bus);
358359
struct klist_iter i;
359360
struct device *dev;
360361
int error = 0;
361362

362-
if (!bus || !bus->p)
363+
if (!sp)
363364
return -EINVAL;
364365

365-
klist_iter_init_node(&bus->p->klist_devices, &i,
366+
klist_iter_init_node(&sp->klist_devices, &i,
366367
(start ? &start->p->knode_bus : NULL));
367368
while (!error && (dev = next_device(&i)))
368369
error = fn(dev, data);
369370
klist_iter_exit(&i);
371+
subsys_put(sp);
370372
return error;
371373
}
372374
EXPORT_SYMBOL_GPL(bus_for_each_dev);
@@ -390,18 +392,20 @@ struct device *bus_find_device(const struct bus_type *bus,
390392
struct device *start, const void *data,
391393
int (*match)(struct device *dev, const void *data))
392394
{
395+
struct subsys_private *sp = bus_to_subsys(bus);
393396
struct klist_iter i;
394397
struct device *dev;
395398

396-
if (!bus || !bus->p)
399+
if (!sp)
397400
return NULL;
398401

399-
klist_iter_init_node(&bus->p->klist_devices, &i,
402+
klist_iter_init_node(&sp->klist_devices, &i,
400403
(start ? &start->p->knode_bus : NULL));
401404
while ((dev = next_device(&i)))
402405
if (match(dev, data) && get_device(dev))
403406
break;
404407
klist_iter_exit(&i);
408+
subsys_put(sp);
405409
return dev;
406410
}
407411
EXPORT_SYMBOL_GPL(bus_find_device);
@@ -440,18 +444,20 @@ static struct device_driver *next_driver(struct klist_iter *i)
440444
int bus_for_each_drv(const struct bus_type *bus, struct device_driver *start,
441445
void *data, int (*fn)(struct device_driver *, void *))
442446
{
447+
struct subsys_private *sp = bus_to_subsys(bus);
443448
struct klist_iter i;
444449
struct device_driver *drv;
445450
int error = 0;
446451

447-
if (!bus)
452+
if (!sp)
448453
return -EINVAL;
449454

450-
klist_iter_init_node(&bus->p->klist_drivers, &i,
455+
klist_iter_init_node(&sp->klist_drivers, &i,
451456
start ? &start->p->knode_bus : NULL);
452457
while ((drv = next_driver(&i)) && !error)
453458
error = fn(drv, data);
454459
klist_iter_exit(&i);
460+
subsys_put(sp);
455461
return error;
456462
}
457463
EXPORT_SYMBOL_GPL(bus_for_each_drv);

0 commit comments

Comments
 (0)