31
31
32
32
*/
33
33
34
+ #include <linux/cleanup.h>
34
35
#include <linux/module.h>
35
36
#include <linux/pci.h>
36
37
#include <linux/spinlock.h>
@@ -69,10 +70,9 @@ MODULE_PARM_DESC(gpiobase, "The GPIO number base. -1 means dynamic, which is the
69
70
static int bt8xxgpio_gpio_direction_input (struct gpio_chip * gpio , unsigned nr )
70
71
{
71
72
struct bt8xxgpio * bg = gpiochip_get_data (gpio );
72
- unsigned long flags ;
73
73
u32 outen , data ;
74
74
75
- spin_lock_irqsave ( & bg -> lock , flags );
75
+ guard ( spinlock_irqsave )( & bg -> lock );
76
76
77
77
data = bgread (BT848_GPIO_DATA );
78
78
data &= ~(1 << nr );
@@ -82,20 +82,17 @@ static int bt8xxgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
82
82
outen &= ~(1 << nr );
83
83
bgwrite (outen , BT848_GPIO_OUT_EN );
84
84
85
- spin_unlock_irqrestore (& bg -> lock , flags );
86
-
87
85
return 0 ;
88
86
}
89
87
90
88
static int bt8xxgpio_gpio_get (struct gpio_chip * gpio , unsigned nr )
91
89
{
92
90
struct bt8xxgpio * bg = gpiochip_get_data (gpio );
93
- unsigned long flags ;
94
91
u32 val ;
95
92
96
- spin_lock_irqsave (& bg -> lock , flags );
93
+ guard (spinlock_irqsave )(& bg -> lock );
94
+
97
95
val = bgread (BT848_GPIO_DATA );
98
- spin_unlock_irqrestore (& bg -> lock , flags );
99
96
100
97
return !!(val & (1 << nr ));
101
98
}
@@ -104,10 +101,9 @@ static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio,
104
101
unsigned nr , int val )
105
102
{
106
103
struct bt8xxgpio * bg = gpiochip_get_data (gpio );
107
- unsigned long flags ;
108
104
u32 outen , data ;
109
105
110
- spin_lock_irqsave ( & bg -> lock , flags );
106
+ guard ( spinlock_irqsave )( & bg -> lock );
111
107
112
108
outen = bgread (BT848_GPIO_OUT_EN );
113
109
outen |= (1 << nr );
@@ -120,28 +116,23 @@ static int bt8xxgpio_gpio_direction_output(struct gpio_chip *gpio,
120
116
data &= ~(1 << nr );
121
117
bgwrite (data , BT848_GPIO_DATA );
122
118
123
- spin_unlock_irqrestore (& bg -> lock , flags );
124
-
125
119
return 0 ;
126
120
}
127
121
128
122
static void bt8xxgpio_gpio_set (struct gpio_chip * gpio ,
129
123
unsigned nr , int val )
130
124
{
131
125
struct bt8xxgpio * bg = gpiochip_get_data (gpio );
132
- unsigned long flags ;
133
126
u32 data ;
134
127
135
- spin_lock_irqsave ( & bg -> lock , flags );
128
+ guard ( spinlock_irqsave )( & bg -> lock );
136
129
137
130
data = bgread (BT848_GPIO_DATA );
138
131
if (val )
139
132
data |= (1 << nr );
140
133
else
141
134
data &= ~(1 << nr );
142
135
bgwrite (data , BT848_GPIO_DATA );
143
-
144
- spin_unlock_irqrestore (& bg -> lock , flags );
145
136
}
146
137
147
138
static void bt8xxgpio_gpio_setup (struct bt8xxgpio * bg )
@@ -236,18 +227,15 @@ static void bt8xxgpio_remove(struct pci_dev *pdev)
236
227
static int bt8xxgpio_suspend (struct pci_dev * pdev , pm_message_t state )
237
228
{
238
229
struct bt8xxgpio * bg = pci_get_drvdata (pdev );
239
- unsigned long flags ;
240
-
241
- spin_lock_irqsave (& bg -> lock , flags );
242
230
243
- bg -> saved_outen = bgread (BT848_GPIO_OUT_EN );
244
- bg -> saved_data = bgread (BT848_GPIO_DATA );
231
+ scoped_guard (spinlock_irqsave , & bg -> lock ) {
232
+ bg -> saved_outen = bgread (BT848_GPIO_OUT_EN );
233
+ bg -> saved_data = bgread (BT848_GPIO_DATA );
245
234
246
- bgwrite (0 , BT848_INT_MASK );
247
- bgwrite (~0x0 , BT848_INT_STAT );
248
- bgwrite (0x0 , BT848_GPIO_OUT_EN );
249
-
250
- spin_unlock_irqrestore (& bg -> lock , flags );
235
+ bgwrite (0 , BT848_INT_MASK );
236
+ bgwrite (~0x0 , BT848_INT_STAT );
237
+ bgwrite (0x0 , BT848_GPIO_OUT_EN );
238
+ }
251
239
252
240
pci_save_state (pdev );
253
241
pci_disable_device (pdev );
@@ -259,7 +247,6 @@ static int bt8xxgpio_suspend(struct pci_dev *pdev, pm_message_t state)
259
247
static int bt8xxgpio_resume (struct pci_dev * pdev )
260
248
{
261
249
struct bt8xxgpio * bg = pci_get_drvdata (pdev );
262
- unsigned long flags ;
263
250
int err ;
264
251
265
252
pci_set_power_state (pdev , PCI_D0 );
@@ -268,7 +255,7 @@ static int bt8xxgpio_resume(struct pci_dev *pdev)
268
255
return err ;
269
256
pci_restore_state (pdev );
270
257
271
- spin_lock_irqsave ( & bg -> lock , flags );
258
+ guard ( spinlock_irqsave )( & bg -> lock );
272
259
273
260
bgwrite (0 , BT848_INT_MASK );
274
261
bgwrite (0 , BT848_GPIO_DMA_CTL );
@@ -277,8 +264,6 @@ static int bt8xxgpio_resume(struct pci_dev *pdev)
277
264
bgwrite (bg -> saved_data & bg -> saved_outen ,
278
265
BT848_GPIO_DATA );
279
266
280
- spin_unlock_irqrestore (& bg -> lock , flags );
281
-
282
267
return 0 ;
283
268
}
284
269
#else
0 commit comments