Skip to content

Commit 1d90e6c

Browse files
committed
ipmi: Consolidate the run to completion checking for xmit msgs lock
It made things hard to read, move the check to a function. Signed-off-by: Corey Minyard <corey@minyard.net> Reviewed-by: Breno Leitao <leitao@debian.org>
1 parent 594c11d commit 1d90e6c

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,22 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf,
602602
static int __scan_channels(struct ipmi_smi *intf,
603603
struct ipmi_device_id *id, bool rescan);
604604

605+
static void ipmi_lock_xmit_msgs(struct ipmi_smi *intf, int run_to_completion,
606+
unsigned long *flags)
607+
{
608+
if (run_to_completion)
609+
return;
610+
spin_lock_irqsave(&intf->xmit_msgs_lock, *flags);
611+
}
612+
613+
static void ipmi_unlock_xmit_msgs(struct ipmi_smi *intf, int run_to_completion,
614+
unsigned long *flags)
615+
{
616+
if (run_to_completion)
617+
return;
618+
spin_unlock_irqrestore(&intf->xmit_msgs_lock, *flags);
619+
}
620+
605621
static void free_ipmi_user(struct kref *ref)
606622
{
607623
struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount);
@@ -1878,11 +1894,9 @@ static void smi_send(struct ipmi_smi *intf,
18781894
int run_to_completion = READ_ONCE(intf->run_to_completion);
18791895
unsigned long flags = 0;
18801896

1881-
if (!run_to_completion)
1882-
spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
1897+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
18831898
smi_msg = smi_add_send_msg(intf, smi_msg, priority);
1884-
if (!run_to_completion)
1885-
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
1899+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
18861900

18871901
if (smi_msg)
18881902
handlers->sender(intf->send_info, smi_msg);
@@ -4826,8 +4840,7 @@ static void smi_work(struct work_struct *t)
48264840
* message delivery.
48274841
*/
48284842
restart:
4829-
if (!run_to_completion)
4830-
spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
4843+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
48314844
if (intf->curr_msg == NULL && !intf->in_shutdown) {
48324845
struct list_head *entry = NULL;
48334846

@@ -4843,22 +4856,17 @@ static void smi_work(struct work_struct *t)
48434856
intf->curr_msg = newmsg;
48444857
}
48454858
}
4846-
if (!run_to_completion)
4847-
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
4859+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
48484860

48494861
if (newmsg) {
48504862
cc = intf->handlers->sender(intf->send_info, newmsg);
48514863
if (cc) {
48524864
if (newmsg->recv_msg)
48534865
deliver_err_response(intf,
48544866
newmsg->recv_msg, cc);
4855-
if (!run_to_completion)
4856-
spin_lock_irqsave(&intf->xmit_msgs_lock,
4857-
flags);
4867+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
48584868
intf->curr_msg = NULL;
4859-
if (!run_to_completion)
4860-
spin_unlock_irqrestore(&intf->xmit_msgs_lock,
4861-
flags);
4869+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
48624870
ipmi_free_smi_msg(newmsg);
48634871
newmsg = NULL;
48644872
goto restart;
@@ -4928,16 +4936,14 @@ void ipmi_smi_msg_received(struct ipmi_smi *intf,
49284936
spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock,
49294937
flags);
49304938

4931-
if (!run_to_completion)
4932-
spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
4939+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
49334940
/*
49344941
* We can get an asynchronous event or receive message in addition
49354942
* to commands we send.
49364943
*/
49374944
if (msg == intf->curr_msg)
49384945
intf->curr_msg = NULL;
4939-
if (!run_to_completion)
4940-
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
4946+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
49414947

49424948
if (run_to_completion)
49434949
smi_work(&intf->smi_work);

0 commit comments

Comments
 (0)