@@ -85,7 +85,7 @@ static DEFINE_MUTEX(gpio_lookup_lock);
85
85
static LIST_HEAD (gpio_lookup_list );
86
86
87
87
LIST_HEAD (gpio_devices );
88
- DEFINE_MUTEX ( gpio_devices_lock );
88
+ DECLARE_RWSEM ( gpio_devices_sem );
89
89
90
90
static DEFINE_MUTEX (gpio_machine_hogs_mutex );
91
91
static LIST_HEAD (gpio_machine_hogs );
@@ -118,7 +118,7 @@ struct gpio_desc *gpio_to_desc(unsigned gpio)
118
118
{
119
119
struct gpio_device * gdev ;
120
120
121
- scoped_guard (mutex , & gpio_devices_lock ) {
121
+ scoped_guard (rwsem_read , & gpio_devices_sem ) {
122
122
list_for_each_entry (gdev , & gpio_devices , list ) {
123
123
if (gdev -> base <= gpio &&
124
124
gdev -> base + gdev -> ngpio > gpio )
@@ -402,7 +402,7 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
402
402
if (!name )
403
403
return NULL ;
404
404
405
- guard (mutex )(& gpio_devices_lock );
405
+ guard (rwsem_read )(& gpio_devices_sem );
406
406
407
407
list_for_each_entry (gdev , & gpio_devices , list ) {
408
408
struct gpio_desc * desc ;
@@ -871,7 +871,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
871
871
872
872
gdev -> ngpio = gc -> ngpio ;
873
873
874
- scoped_guard (mutex , & gpio_devices_lock ) {
874
+ scoped_guard (rwsem_write , & gpio_devices_sem ) {
875
875
/*
876
876
* TODO: this allocates a Linux GPIO number base in the global
877
877
* GPIO numberspace for this chip. In the long run we want to
@@ -1001,7 +1001,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
1001
1001
goto err_print_message ;
1002
1002
}
1003
1003
err_remove_from_list :
1004
- scoped_guard (mutex , & gpio_devices_lock )
1004
+ scoped_guard (rwsem_write , & gpio_devices_sem )
1005
1005
list_del (& gdev -> list );
1006
1006
err_free_label :
1007
1007
kfree_const (gdev -> label );
@@ -1065,7 +1065,7 @@ void gpiochip_remove(struct gpio_chip *gc)
1065
1065
dev_crit (& gdev -> dev ,
1066
1066
"REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n" );
1067
1067
1068
- scoped_guard (mutex , & gpio_devices_lock )
1068
+ scoped_guard (rwsem_write , & gpio_devices_sem )
1069
1069
list_del (& gdev -> list );
1070
1070
1071
1071
/*
@@ -1114,7 +1114,7 @@ struct gpio_device *gpio_device_find(void *data,
1114
1114
*/
1115
1115
might_sleep ();
1116
1116
1117
- guard (mutex )(& gpio_devices_lock );
1117
+ guard (rwsem_read )(& gpio_devices_sem );
1118
1118
1119
1119
list_for_each_entry (gdev , & gpio_devices , list ) {
1120
1120
if (gdev -> chip && match (gdev -> chip , data ))
@@ -4730,7 +4730,7 @@ static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos)
4730
4730
4731
4731
s -> private = "" ;
4732
4732
4733
- guard (mutex )(& gpio_devices_lock );
4733
+ guard (rwsem_read )(& gpio_devices_sem );
4734
4734
4735
4735
list_for_each_entry (gdev , & gpio_devices , list ) {
4736
4736
if (index -- == 0 )
@@ -4745,7 +4745,7 @@ static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos)
4745
4745
struct gpio_device * gdev = v ;
4746
4746
void * ret = NULL ;
4747
4747
4748
- scoped_guard (mutex , & gpio_devices_lock ) {
4748
+ scoped_guard (rwsem_read , & gpio_devices_sem ) {
4749
4749
if (list_is_last (& gdev -> list , & gpio_devices ))
4750
4750
ret = NULL ;
4751
4751
else
0 commit comments