@@ -477,12 +477,6 @@ static LIST_HEAD(spi_controller_list);
477
477
*/
478
478
static DEFINE_MUTEX (board_lock );
479
479
480
- /*
481
- * Prevents addition of devices with same chip select and
482
- * addition of devices below an unregistering controller.
483
- */
484
- static DEFINE_MUTEX (spi_add_lock );
485
-
486
480
/**
487
481
* spi_alloc_device - Allocate a new SPI device
488
482
* @ctlr: Controller to which device is connected
@@ -635,9 +629,9 @@ static int spi_add_device(struct spi_device *spi)
635
629
/* Set the bus ID string */
636
630
spi_dev_set_name (spi );
637
631
638
- mutex_lock (& spi_add_lock );
632
+ mutex_lock (& ctlr -> add_lock );
639
633
status = __spi_add_device (spi );
640
- mutex_unlock (& spi_add_lock );
634
+ mutex_unlock (& ctlr -> add_lock );
641
635
return status ;
642
636
}
643
637
@@ -656,7 +650,7 @@ static int spi_add_device_locked(struct spi_device *spi)
656
650
/* Set the bus ID string */
657
651
spi_dev_set_name (spi );
658
652
659
- WARN_ON (!mutex_is_locked (& spi_add_lock ));
653
+ WARN_ON (!mutex_is_locked (& ctlr -> add_lock ));
660
654
return __spi_add_device (spi );
661
655
}
662
656
@@ -2632,6 +2626,12 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
2632
2626
return NULL ;
2633
2627
2634
2628
device_initialize (& ctlr -> dev );
2629
+ INIT_LIST_HEAD (& ctlr -> queue );
2630
+ spin_lock_init (& ctlr -> queue_lock );
2631
+ spin_lock_init (& ctlr -> bus_lock_spinlock );
2632
+ mutex_init (& ctlr -> bus_lock_mutex );
2633
+ mutex_init (& ctlr -> io_mutex );
2634
+ mutex_init (& ctlr -> add_lock );
2635
2635
ctlr -> bus_num = -1 ;
2636
2636
ctlr -> num_chipselect = 1 ;
2637
2637
ctlr -> slave = slave ;
@@ -2904,11 +2904,6 @@ int spi_register_controller(struct spi_controller *ctlr)
2904
2904
return id ;
2905
2905
ctlr -> bus_num = id ;
2906
2906
}
2907
- INIT_LIST_HEAD (& ctlr -> queue );
2908
- spin_lock_init (& ctlr -> queue_lock );
2909
- spin_lock_init (& ctlr -> bus_lock_spinlock );
2910
- mutex_init (& ctlr -> bus_lock_mutex );
2911
- mutex_init (& ctlr -> io_mutex );
2912
2907
ctlr -> bus_lock_flag = 0 ;
2913
2908
init_completion (& ctlr -> xfer_completion );
2914
2909
if (!ctlr -> max_dma_len )
@@ -3045,7 +3040,7 @@ void spi_unregister_controller(struct spi_controller *ctlr)
3045
3040
3046
3041
/* Prevent addition of new devices, unregister existing ones */
3047
3042
if (IS_ENABLED (CONFIG_SPI_DYNAMIC ))
3048
- mutex_lock (& spi_add_lock );
3043
+ mutex_lock (& ctlr -> add_lock );
3049
3044
3050
3045
device_for_each_child (& ctlr -> dev , NULL , __unregister );
3051
3046
@@ -3076,7 +3071,7 @@ void spi_unregister_controller(struct spi_controller *ctlr)
3076
3071
mutex_unlock (& board_lock );
3077
3072
3078
3073
if (IS_ENABLED (CONFIG_SPI_DYNAMIC ))
3079
- mutex_unlock (& spi_add_lock );
3074
+ mutex_unlock (& ctlr -> add_lock );
3080
3075
}
3081
3076
EXPORT_SYMBOL_GPL (spi_unregister_controller );
3082
3077
0 commit comments