@@ -126,7 +126,7 @@ int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel)
126126 int timeout = 0 ;
127127
128128 /* get codec */
129- mutex_lock (& wm -> codec_mutex );
129+ guard ( mutex ) (& wm -> codec_mutex );
130130
131131 /* When the touchscreen is not in use, we may have to power up
132132 * the AUX ADC before we can use sample the AUX inputs->
@@ -160,7 +160,6 @@ int wm97xx_read_aux_adc(struct wm97xx *wm, u16 adcsel)
160160 wm -> codec -> dig_enable (wm , false);
161161 }
162162
163- mutex_unlock (& wm -> codec_mutex );
164163 return (rc == RC_VALID ? auxval & 0xfff : - EBUSY );
165164}
166165EXPORT_SYMBOL_GPL (wm97xx_read_aux_adc );
@@ -176,18 +175,11 @@ EXPORT_SYMBOL_GPL(wm97xx_read_aux_adc);
176175enum wm97xx_gpio_status wm97xx_get_gpio (struct wm97xx * wm , u32 gpio )
177176{
178177 u16 status ;
179- enum wm97xx_gpio_status ret ;
180178
181- mutex_lock (& wm -> codec_mutex );
182- status = wm97xx_reg_read (wm , AC97_GPIO_STATUS );
183-
184- if (status & gpio )
185- ret = WM97XX_GPIO_HIGH ;
186- else
187- ret = WM97XX_GPIO_LOW ;
179+ guard (mutex )(& wm -> codec_mutex );
188180
189- mutex_unlock ( & wm -> codec_mutex );
190- return ret ;
181+ status = wm97xx_reg_read ( wm , AC97_GPIO_STATUS );
182+ return ( status & gpio ) ? WM97XX_GPIO_HIGH : WM97XX_GPIO_LOW ;
191183}
192184EXPORT_SYMBOL_GPL (wm97xx_get_gpio );
193185
@@ -205,7 +197,8 @@ void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
205197{
206198 u16 reg ;
207199
208- mutex_lock (& wm -> codec_mutex );
200+ guard (mutex )(& wm -> codec_mutex );
201+
209202 reg = wm97xx_reg_read (wm , AC97_GPIO_STATUS );
210203
211204 if (status == WM97XX_GPIO_HIGH )
@@ -217,7 +210,6 @@ void wm97xx_set_gpio(struct wm97xx *wm, u32 gpio,
217210 wm97xx_reg_write (wm , AC97_GPIO_STATUS , reg << 1 );
218211 else
219212 wm97xx_reg_write (wm , AC97_GPIO_STATUS , reg );
220- mutex_unlock (& wm -> codec_mutex );
221213}
222214EXPORT_SYMBOL_GPL (wm97xx_set_gpio );
223215
@@ -231,7 +223,8 @@ void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, enum wm97xx_gpio_dir dir,
231223{
232224 u16 reg ;
233225
234- mutex_lock (& wm -> codec_mutex );
226+ guard (mutex )(& wm -> codec_mutex );
227+
235228 reg = wm97xx_reg_read (wm , AC97_GPIO_POLARITY );
236229
237230 if (pol == WM97XX_GPIO_POL_HIGH )
@@ -264,7 +257,6 @@ void wm97xx_config_gpio(struct wm97xx *wm, u32 gpio, enum wm97xx_gpio_dir dir,
264257 reg &= ~gpio ;
265258
266259 wm97xx_reg_write (wm , AC97_GPIO_CFG , reg );
267- mutex_unlock (& wm -> codec_mutex );
268260}
269261EXPORT_SYMBOL_GPL (wm97xx_config_gpio );
270262
@@ -303,7 +295,9 @@ static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id)
303295 wm -> pen_is_down = 0 ;
304296 } else {
305297 u16 status , pol ;
306- mutex_lock (& wm -> codec_mutex );
298+
299+ guard (mutex )(& wm -> codec_mutex );
300+
307301 status = wm97xx_reg_read (wm , AC97_GPIO_STATUS );
308302 pol = wm97xx_reg_read (wm , AC97_GPIO_POLARITY );
309303
@@ -323,7 +317,6 @@ static irqreturn_t wm97xx_pen_interrupt(int irq, void *dev_id)
323317 else
324318 wm97xx_reg_write (wm , AC97_GPIO_STATUS , status &
325319 ~WM97XX_GPIO_13 );
326- mutex_unlock (& wm -> codec_mutex );
327320 }
328321
329322 /* If the system is not using continuous mode or it provides a
@@ -382,7 +375,7 @@ static int wm97xx_read_samples(struct wm97xx *wm)
382375 struct wm97xx_data data ;
383376 int rc ;
384377
385- mutex_lock (& wm -> codec_mutex );
378+ guard ( mutex ) (& wm -> codec_mutex );
386379
387380 if (wm -> mach_ops && wm -> mach_ops -> acc_enabled )
388381 rc = wm -> mach_ops -> acc_pen_down (wm );
@@ -422,8 +415,7 @@ static int wm97xx_read_samples(struct wm97xx *wm)
422415 abs_y [0 ] > (data .y & 0xfff ) ||
423416 abs_y [1 ] < (data .y & 0xfff )) {
424417 dev_dbg (wm -> dev , "Measurement out of range, dropping it\n" );
425- rc = RC_AGAIN ;
426- goto out ;
418+ return RC_AGAIN ;
427419 }
428420
429421 input_report_abs (wm -> input_dev , ABS_X , data .x & 0xfff );
@@ -439,8 +431,6 @@ static int wm97xx_read_samples(struct wm97xx *wm)
439431 wm -> ts_reader_interval = wm -> ts_reader_min_interval ;
440432 }
441433
442- out :
443- mutex_unlock (& wm -> codec_mutex );
444434 return rc ;
445435}
446436
@@ -773,7 +763,8 @@ static int wm97xx_suspend(struct device *dev)
773763 else
774764 suspend_mode = 0 ;
775765
776- mutex_lock (& wm -> input_dev -> mutex );
766+ guard (mutex )(& wm -> input_dev -> mutex );
767+
777768 if (input_device_enabled (wm -> input_dev ))
778769 cancel_delayed_work_sync (& wm -> ts_reader );
779770
@@ -791,7 +782,6 @@ static int wm97xx_suspend(struct device *dev)
791782 reg = wm97xx_reg_read (wm , AC97_EXTENDED_MID ) | 0x8000 ;
792783 wm97xx_reg_write (wm , AC97_EXTENDED_MID , reg );
793784 }
794- mutex_unlock (& wm -> input_dev -> mutex );
795785
796786 return 0 ;
797787}
@@ -800,7 +790,8 @@ static int wm97xx_resume(struct device *dev)
800790{
801791 struct wm97xx * wm = dev_get_drvdata (dev );
802792
803- mutex_lock (& wm -> input_dev -> mutex );
793+ guard (mutex )(& wm -> input_dev -> mutex );
794+
804795 /* restore digitiser and gpios */
805796 if (wm -> id == WM9713_ID2 ) {
806797 wm97xx_reg_write (wm , AC97_WM9713_DIG1 , wm -> dig [0 ]);
@@ -827,7 +818,6 @@ static int wm97xx_resume(struct device *dev)
827818 queue_delayed_work (wm -> ts_workq , & wm -> ts_reader ,
828819 wm -> ts_reader_interval );
829820 }
830- mutex_unlock (& wm -> input_dev -> mutex );
831821
832822 return 0 ;
833823}
@@ -840,23 +830,22 @@ static DEFINE_SIMPLE_DEV_PM_OPS(wm97xx_pm_ops, wm97xx_suspend, wm97xx_resume);
840830int wm97xx_register_mach_ops (struct wm97xx * wm ,
841831 struct wm97xx_mach_ops * mach_ops )
842832{
843- mutex_lock (& wm -> codec_mutex );
844- if ( wm -> mach_ops ) {
845- mutex_unlock ( & wm -> codec_mutex );
833+ guard ( mutex ) (& wm -> codec_mutex );
834+
835+ if ( wm -> mach_ops )
846836 return - EINVAL ;
847- }
837+
848838 wm -> mach_ops = mach_ops ;
849- mutex_unlock (& wm -> codec_mutex );
850839
851840 return 0 ;
852841}
853842EXPORT_SYMBOL_GPL (wm97xx_register_mach_ops );
854843
855844void wm97xx_unregister_mach_ops (struct wm97xx * wm )
856845{
857- mutex_lock (& wm -> codec_mutex );
846+ guard (mutex )(& wm -> codec_mutex );
847+
858848 wm -> mach_ops = NULL ;
859- mutex_unlock (& wm -> codec_mutex );
860849}
861850EXPORT_SYMBOL_GPL (wm97xx_unregister_mach_ops );
862851
0 commit comments