66 * Author: Jassi Brar <jassisinghbrar@gmail.com>
77 */
88
9+ #include <linux/cleanup.h>
910#include <linux/delay.h>
1011#include <linux/device.h>
1112#include <linux/err.h>
@@ -370,13 +371,9 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
370371 */
371372int mbox_bind_client (struct mbox_chan * chan , struct mbox_client * cl )
372373{
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 );
378375
379- return ret ;
376+ return __mbox_bind_client ( chan , cl ) ;
380377}
381378EXPORT_SYMBOL_GPL (mbox_bind_client );
382379
@@ -417,28 +414,25 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
417414 return ERR_PTR (ret );
418415 }
419416
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+ }
421425
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 );
429427
430- of_node_put (spec .np );
428+ if (IS_ERR (chan ))
429+ return chan ;
431430
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 ) ;
435434 }
436435
437- ret = __mbox_bind_client (chan , cl );
438- if (ret )
439- chan = ERR_PTR (ret );
440-
441- mutex_unlock (& con_mutex );
442436 return chan ;
443437}
444438EXPORT_SYMBOL_GPL (mbox_request_channel );
@@ -547,9 +541,8 @@ int mbox_controller_register(struct mbox_controller *mbox)
547541 if (!mbox -> of_xlate )
548542 mbox -> of_xlate = of_mbox_index_xlate ;
549543
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 );
553546
554547 return 0 ;
555548}
@@ -566,17 +559,15 @@ void mbox_controller_unregister(struct mbox_controller *mbox)
566559 if (!mbox )
567560 return ;
568561
569- mutex_lock (& con_mutex );
570-
571- list_del (& mbox -> node );
562+ scoped_guard (mutex , & con_mutex ) {
563+ list_del (& mbox -> node );
572564
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 ]);
575567
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+ }
580571}
581572EXPORT_SYMBOL_GPL (mbox_controller_unregister );
582573
0 commit comments