Skip to contentSkip to conversation

ipmi: simplify duplicated if condition

PATCH In review Wan Jiabing 2 participants 2 messages Oct 25, 2021 IPMI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipmi: simplify duplicated if condition

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.

---
 drivers/char/ipmi/ipmi_msghandler.c | 38 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +18 -20
index a60201d3f735..072da25124cf 100644
@@ -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);
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 2 lines · Wan Jiabing

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

It's modified in panic_event().

Quoted 6 lines

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.

I'm not sure this matters that much. The comments are messed up a bit, and probably need to be reworked. But I'm not inclined to take this.

-corey

Quoted 64 lines
---
 drivers/char/ipmi/ipmi_msghandler.c | 38 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +18 -20
index a60201d3f735..072da25124cf 100644
@@ -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);
 
Signature · 1 line
2.20.1