mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
mailbox: Use guard/scoped_guard for con_mutex
Use guard and scoped_guard for con_mutex to simplify code. Signed-off-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
This commit is contained in:
parent
9be022476f
commit
16da9a653c
1 changed files with 26 additions and 35 deletions
|
@ -6,6 +6,7 @@
|
||||||
* Author: Jassi Brar <jassisinghbrar@gmail.com>
|
* Author: Jassi Brar <jassisinghbrar@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
@ -370,13 +371,9 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
|
||||||
*/
|
*/
|
||||||
int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
|
int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
|
||||||
{
|
{
|
||||||
int ret;
|
guard(mutex)(&con_mutex);
|
||||||
|
|
||||||
mutex_lock(&con_mutex);
|
return __mbox_bind_client(chan, cl);
|
||||||
ret = __mbox_bind_client(chan, cl);
|
|
||||||
mutex_unlock(&con_mutex);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mbox_bind_client);
|
EXPORT_SYMBOL_GPL(mbox_bind_client);
|
||||||
|
|
||||||
|
@ -417,28 +414,25 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&con_mutex);
|
scoped_guard(mutex, &con_mutex) {
|
||||||
|
chan = ERR_PTR(-EPROBE_DEFER);
|
||||||
|
list_for_each_entry(mbox, &mbox_cons, node)
|
||||||
|
if (mbox->dev->of_node == spec.np) {
|
||||||
|
chan = mbox->of_xlate(mbox, &spec);
|
||||||
|
if (!IS_ERR(chan))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
chan = ERR_PTR(-EPROBE_DEFER);
|
of_node_put(spec.np);
|
||||||
list_for_each_entry(mbox, &mbox_cons, node)
|
|
||||||
if (mbox->dev->of_node == spec.np) {
|
|
||||||
chan = mbox->of_xlate(mbox, &spec);
|
|
||||||
if (!IS_ERR(chan))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
of_node_put(spec.np);
|
if (IS_ERR(chan))
|
||||||
|
return chan;
|
||||||
|
|
||||||
if (IS_ERR(chan)) {
|
ret = __mbox_bind_client(chan, cl);
|
||||||
mutex_unlock(&con_mutex);
|
if (ret)
|
||||||
return chan;
|
chan = ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = __mbox_bind_client(chan, cl);
|
|
||||||
if (ret)
|
|
||||||
chan = ERR_PTR(ret);
|
|
||||||
|
|
||||||
mutex_unlock(&con_mutex);
|
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mbox_request_channel);
|
EXPORT_SYMBOL_GPL(mbox_request_channel);
|
||||||
|
@ -547,9 +541,8 @@ int mbox_controller_register(struct mbox_controller *mbox)
|
||||||
if (!mbox->of_xlate)
|
if (!mbox->of_xlate)
|
||||||
mbox->of_xlate = of_mbox_index_xlate;
|
mbox->of_xlate = of_mbox_index_xlate;
|
||||||
|
|
||||||
mutex_lock(&con_mutex);
|
scoped_guard(mutex, &con_mutex)
|
||||||
list_add_tail(&mbox->node, &mbox_cons);
|
list_add_tail(&mbox->node, &mbox_cons);
|
||||||
mutex_unlock(&con_mutex);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -566,17 +559,15 @@ void mbox_controller_unregister(struct mbox_controller *mbox)
|
||||||
if (!mbox)
|
if (!mbox)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mutex_lock(&con_mutex);
|
scoped_guard(mutex, &con_mutex) {
|
||||||
|
list_del(&mbox->node);
|
||||||
|
|
||||||
list_del(&mbox->node);
|
for (i = 0; i < mbox->num_chans; i++)
|
||||||
|
mbox_free_channel(&mbox->chans[i]);
|
||||||
|
|
||||||
for (i = 0; i < mbox->num_chans; i++)
|
if (mbox->txdone_poll)
|
||||||
mbox_free_channel(&mbox->chans[i]);
|
hrtimer_cancel(&mbox->poll_hrt);
|
||||||
|
}
|
||||||
if (mbox->txdone_poll)
|
|
||||||
hrtimer_cancel(&mbox->poll_hrt);
|
|
||||||
|
|
||||||
mutex_unlock(&con_mutex);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mbox_controller_unregister);
|
EXPORT_SYMBOL_GPL(mbox_controller_unregister);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue