6
6
* Author: Jassi Brar <[email protected] >
7
7
*/
8
8
9
+ #include <linux/cleanup.h>
9
10
#include <linux/delay.h>
10
11
#include <linux/device.h>
11
12
#include <linux/err.h>
@@ -370,13 +371,9 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
370
371
*/
371
372
int mbox_bind_client (struct mbox_chan * chan , struct mbox_client * cl )
372
373
{
373
- int ret ;
374
-
375
- mutex_lock (& con_mutex );
376
- ret = __mbox_bind_client (chan , cl );
377
- mutex_unlock (& con_mutex );
374
+ guard (mutex )(& con_mutex );
378
375
379
- return ret ;
376
+ return __mbox_bind_client ( chan , cl ) ;
380
377
}
381
378
EXPORT_SYMBOL_GPL (mbox_bind_client );
382
379
@@ -417,28 +414,25 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
417
414
return ERR_PTR (ret );
418
415
}
419
416
420
- mutex_lock (& con_mutex );
417
+ scoped_guard (mutex , & con_mutex ) {
418
+ chan = ERR_PTR (- EPROBE_DEFER );
419
+ list_for_each_entry (mbox , & mbox_cons , node )
420
+ if (mbox -> dev -> of_node == spec .np ) {
421
+ chan = mbox -> of_xlate (mbox , & spec );
422
+ if (!IS_ERR (chan ))
423
+ break ;
424
+ }
421
425
422
- chan = ERR_PTR (- EPROBE_DEFER );
423
- list_for_each_entry (mbox , & mbox_cons , node )
424
- if (mbox -> dev -> of_node == spec .np ) {
425
- chan = mbox -> of_xlate (mbox , & spec );
426
- if (!IS_ERR (chan ))
427
- break ;
428
- }
426
+ of_node_put (spec .np );
429
427
430
- of_node_put (spec .np );
428
+ if (IS_ERR (chan ))
429
+ return chan ;
431
430
432
- if ( IS_ERR ( chan )) {
433
- mutex_unlock ( & con_mutex );
434
- return chan ;
431
+ ret = __mbox_bind_client ( chan , cl );
432
+ if ( ret )
433
+ chan = ERR_PTR ( ret ) ;
435
434
}
436
435
437
- ret = __mbox_bind_client (chan , cl );
438
- if (ret )
439
- chan = ERR_PTR (ret );
440
-
441
- mutex_unlock (& con_mutex );
442
436
return chan ;
443
437
}
444
438
EXPORT_SYMBOL_GPL (mbox_request_channel );
@@ -547,9 +541,8 @@ int mbox_controller_register(struct mbox_controller *mbox)
547
541
if (!mbox -> of_xlate )
548
542
mbox -> of_xlate = of_mbox_index_xlate ;
549
543
550
- mutex_lock (& con_mutex );
551
- list_add_tail (& mbox -> node , & mbox_cons );
552
- mutex_unlock (& con_mutex );
544
+ scoped_guard (mutex , & con_mutex )
545
+ list_add_tail (& mbox -> node , & mbox_cons );
553
546
554
547
return 0 ;
555
548
}
@@ -566,17 +559,15 @@ void mbox_controller_unregister(struct mbox_controller *mbox)
566
559
if (!mbox )
567
560
return ;
568
561
569
- mutex_lock (& con_mutex );
570
-
571
- list_del (& mbox -> node );
562
+ scoped_guard (mutex , & con_mutex ) {
563
+ list_del (& mbox -> node );
572
564
573
- for (i = 0 ; i < mbox -> num_chans ; i ++ )
574
- mbox_free_channel (& mbox -> chans [i ]);
565
+ for (i = 0 ; i < mbox -> num_chans ; i ++ )
566
+ mbox_free_channel (& mbox -> chans [i ]);
575
567
576
- if (mbox -> txdone_poll )
577
- hrtimer_cancel (& mbox -> poll_hrt );
578
-
579
- mutex_unlock (& con_mutex );
568
+ if (mbox -> txdone_poll )
569
+ hrtimer_cancel (& mbox -> poll_hrt );
570
+ }
580
571
}
581
572
EXPORT_SYMBOL_GPL (mbox_controller_unregister );
582
573
0 commit comments