Skip to content
/ linux Public

Commit 1e363c1

Browse files
cminyardgregkh
authored andcommitted
ipmi: Consolidate the run to completion checking for xmit msgs lock
[ Upstream commit 1d90e6c ] 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> Stable-dep-of: 62cd145 ("ipmi:msghandler: Handle error returns from the SMI sender") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 522acaa commit 1e363c1

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

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);
@@ -4822,8 +4836,7 @@ static void smi_work(struct work_struct *t)
48224836
* message delivery.
48234837
*/
48244838
restart:
4825-
if (!run_to_completion)
4826-
spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
4839+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
48274840
if (intf->curr_msg == NULL && !intf->in_shutdown) {
48284841
struct list_head *entry = NULL;
48294842

@@ -4839,22 +4852,17 @@ static void smi_work(struct work_struct *t)
48394852
intf->curr_msg = newmsg;
48404853
}
48414854
}
4842-
if (!run_to_completion)
4843-
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
4855+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
48444856

48454857
if (newmsg) {
48464858
cc = intf->handlers->sender(intf->send_info, newmsg);
48474859
if (cc) {
48484860
if (newmsg->recv_msg)
48494861
deliver_err_response(intf,
48504862
newmsg->recv_msg, cc);
4851-
if (!run_to_completion)
4852-
spin_lock_irqsave(&intf->xmit_msgs_lock,
4853-
flags);
4863+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
48544864
intf->curr_msg = NULL;
4855-
if (!run_to_completion)
4856-
spin_unlock_irqrestore(&intf->xmit_msgs_lock,
4857-
flags);
4865+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
48584866
ipmi_free_smi_msg(newmsg);
48594867
newmsg = NULL;
48604868
goto restart;
@@ -4924,16 +4932,14 @@ void ipmi_smi_msg_received(struct ipmi_smi *intf,
49244932
spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock,
49254933
flags);
49264934

4927-
if (!run_to_completion)
4928-
spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
4935+
ipmi_lock_xmit_msgs(intf, run_to_completion, &flags);
49294936
/*
49304937
* We can get an asynchronous event or receive message in addition
49314938
* to commands we send.
49324939
*/
49334940
if (msg == intf->curr_msg)
49344941
intf->curr_msg = NULL;
4935-
if (!run_to_completion)
4936-
spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
4942+
ipmi_unlock_xmit_msgs(intf, run_to_completion, &flags);
49374943

49384944
if (run_to_completion)
49394945
smi_work(&intf->smi_work);

0 commit comments

Comments
 (0)