mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wan Jiabing <wanjiabing@vivo.com>
To: Corey Minyard <minyard@acm.org>,
	openipmi-developer@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: kael_w@yeah.net, Wan Jiabing <wanjiabing@vivo.com>
Subject: [PATCH] ipmi: simplify duplicated if condition
Date: Sun, 24 Oct 2021 21:22:06 -0400	[thread overview]
Message-ID: <20211025012206.21189-1-wanjiabing@vivo.com> (raw)

There are 5 duplicated 'if' conditions to judge the 'run_to_completion',
which looks redundant. And there is no function to modify this variable.

Reduce the 'if' conditions from 5 times to 1 time can make code easy to
understand and fix following coccicheck warning:

./drivers/char/ipmi/ipmi_msghandler.c :4771:2-19: ERROR: nested
lock+irqsave that reuses flags from line 4764.

Signed-off-by: Wan Jiabing <wanjiabing@vivo.com>
---
 drivers/char/ipmi/ipmi_msghandler.c | 38 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index a60201d3f735..072da25124cf 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -4756,32 +4756,30 @@ void ipmi_smi_msg_received(struct ipmi_smi *intf,
 	unsigned long flags = 0; /* keep us warning-free. */
 	int run_to_completion = intf->run_to_completion;
 
-	/*
-	 * To preserve message order, we keep a queue and deliver from
-	 * a tasklet.
-	 */
-	if (!run_to_completion)
+	if (!run_to_completion) {
+		/*
+		 * To preserve message order, we keep a queue and deliver from
+		 * a tasklet.
+		 */
 		spin_lock_irqsave(&intf->waiting_rcv_msgs_lock, flags);
-	list_add_tail(&msg->link, &intf->waiting_rcv_msgs);
-	if (!run_to_completion)
+		list_add_tail(&msg->link, &intf->waiting_rcv_msgs);
 		spin_unlock_irqrestore(&intf->waiting_rcv_msgs_lock,
 				       flags);
-
-	if (!run_to_completion)
 		spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
-	/*
-	 * We can get an asynchronous event or receive message in addition
-	 * to commands we send.
-	 */
-	if (msg == intf->curr_msg)
-		intf->curr_msg = NULL;
-	if (!run_to_completion)
+		/*
+		 * We can get an asynchronous event or receive message in addition
+		 * to commands we send.
+		 */
+		if (msg == intf->curr_msg)
+			intf->curr_msg = NULL;
 		spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
-
-	if (run_to_completion)
-		smi_recv_tasklet(&intf->recv_tasklet);
-	else
 		tasklet_schedule(&intf->recv_tasklet);
+	} else {
+		list_add_tail(&msg->link, &intf->waiting_rcv_msgs);
+		if (msg == intf->curr_msg)
+			intf->curr_msg = NULL;
+		smi_recv_tasklet(&intf->recv_tasklet);
+	}
 }
 EXPORT_SYMBOL(ipmi_smi_msg_received);
 
-- 
2.20.1


             reply	other threads:[~2021-10-25  1:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25  1:22 Wan Jiabing [this message]
2021-10-25 21:07 ` Corey Minyard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211025012206.21189-1-wanjiabing@vivo.com \
    --to=wanjiabing@vivo.com \
    --cc=kael_w@yeah.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minyard@acm.org \
    --cc=openipmi-developer@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®