diff options
-rw-r--r-- | drivers/spi/spi.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 93e9de46977a..682a6a48fec3 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -485,6 +485,15 @@ void spi_unregister_master(struct spi_master *master) | |||
485 | } | 485 | } |
486 | EXPORT_SYMBOL_GPL(spi_unregister_master); | 486 | EXPORT_SYMBOL_GPL(spi_unregister_master); |
487 | 487 | ||
488 | static int __spi_master_match(struct device *dev, void *data) | ||
489 | { | ||
490 | struct spi_master *m; | ||
491 | u16 *bus_num = data; | ||
492 | |||
493 | m = container_of(dev, struct spi_master, dev); | ||
494 | return m->bus_num == *bus_num; | ||
495 | } | ||
496 | |||
488 | /** | 497 | /** |
489 | * spi_busnum_to_master - look up master associated with bus_num | 498 | * spi_busnum_to_master - look up master associated with bus_num |
490 | * @bus_num: the master's bus number | 499 | * @bus_num: the master's bus number |
@@ -499,17 +508,12 @@ struct spi_master *spi_busnum_to_master(u16 bus_num) | |||
499 | { | 508 | { |
500 | struct device *dev; | 509 | struct device *dev; |
501 | struct spi_master *master = NULL; | 510 | struct spi_master *master = NULL; |
502 | struct spi_master *m; | 511 | |
503 | 512 | dev = class_find_device(&spi_master_class, &bus_num, | |
504 | down(&spi_master_class.sem); | 513 | __spi_master_match); |
505 | list_for_each_entry(dev, &spi_master_class.children, node) { | 514 | if (dev) |
506 | m = container_of(dev, struct spi_master, dev); | 515 | master = container_of(dev, struct spi_master, dev); |
507 | if (m->bus_num == bus_num) { | 516 | /* reference got in class_find_device */ |
508 | master = spi_master_get(m); | ||
509 | break; | ||
510 | } | ||
511 | } | ||
512 | up(&spi_master_class.sem); | ||
513 | return master; | 517 | return master; |
514 | } | 518 | } |
515 | EXPORT_SYMBOL_GPL(spi_busnum_to_master); | 519 | EXPORT_SYMBOL_GPL(spi_busnum_to_master); |