linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ACPI: ipmi: replace usage of found with dedicated list iterator variable
@ 2022-03-24  7:04 Jakob Koschel
  2022-03-25 17:05 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Jakob Koschel @ 2022-03-24  7:04 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Len Brown, linux-acpi, linux-kernel, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.,
	Jakob Koschel

To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/acpi/acpi_ipmi.c | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c
index a5fe2926bf50..0555f68c2dfd 100644
--- a/drivers/acpi/acpi_ipmi.c
+++ b/drivers/acpi/acpi_ipmi.c
@@ -353,29 +353,27 @@ static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
 static void ipmi_cancel_tx_msg(struct acpi_ipmi_device *ipmi,
 			       struct acpi_ipmi_msg *msg)
 {
-	struct acpi_ipmi_msg *tx_msg, *temp;
-	bool msg_found = false;
+	struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
 	unsigned long flags;
 
 	spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
-	list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
-		if (msg == tx_msg) {
-			msg_found = true;
-			list_del(&tx_msg->head);
+	list_for_each_entry_safe(iter, temp, &ipmi->tx_msg_list, head) {
+		if (msg == iter) {
+			tx_msg = iter;
+			list_del(&iter->head);
 			break;
 		}
 	}
 	spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
 
-	if (msg_found)
+	if (tx_msg)
 		acpi_ipmi_msg_put(tx_msg);
 }
 
 static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
 {
 	struct acpi_ipmi_device *ipmi_device = user_msg_data;
-	bool msg_found = false;
-	struct acpi_ipmi_msg *tx_msg, *temp;
+	struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
 	struct device *dev = ipmi_device->dev;
 	unsigned long flags;
 
@@ -387,16 +385,16 @@ static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
 	}
 
 	spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
-	list_for_each_entry_safe(tx_msg, temp, &ipmi_device->tx_msg_list, head) {
-		if (msg->msgid == tx_msg->tx_msgid) {
-			msg_found = true;
-			list_del(&tx_msg->head);
+	list_for_each_entry_safe(iter, temp, &ipmi_device->tx_msg_list, head) {
+		if (msg->msgid == iter->tx_msgid) {
+			tx_msg = iter;
+			list_del(&iter->head);
 			break;
 		}
 	}
 	spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
 
-	if (!msg_found) {
+	if (!tx_msg) {
 		dev_warn(dev,
 			 "Unexpected response (msg id %ld) is returned.\n",
 			 msg->msgid);
@@ -482,15 +480,14 @@ static void ipmi_register_bmc(int iface, struct device *dev)
 
 static void ipmi_bmc_gone(int iface)
 {
-	struct acpi_ipmi_device *ipmi_device, *temp;
-	bool dev_found = false;
+	struct acpi_ipmi_device *ipmi_device = NULL, *iter, *temp;
 
 	mutex_lock(&driver_data.ipmi_lock);
-	list_for_each_entry_safe(ipmi_device, temp,
+	list_for_each_entry_safe(iter, temp,
 				 &driver_data.ipmi_devices, head) {
-		if (ipmi_device->ipmi_ifnum != iface) {
-			dev_found = true;
-			__ipmi_dev_kill(ipmi_device);
+		if (iter->ipmi_ifnum != iface) {
+			ipmi_device = iter;
+			__ipmi_dev_kill(iter);
 			break;
 		}
 	}
@@ -500,7 +497,7 @@ static void ipmi_bmc_gone(int iface)
 					struct acpi_ipmi_device, head);
 	mutex_unlock(&driver_data.ipmi_lock);
 
-	if (dev_found) {
+	if (ipmi_device) {
 		ipmi_flush_tx_msg(ipmi_device);
 		acpi_ipmi_dev_put(ipmi_device);
 	}

base-commit: f443e374ae131c168a065ea1748feac6b2e76613
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ACPI: ipmi: replace usage of found with dedicated list iterator variable
  2022-03-24  7:04 [PATCH] ACPI: ipmi: replace usage of found with dedicated list iterator variable Jakob Koschel
@ 2022-03-25 17:05 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2022-03-25 17:05 UTC (permalink / raw)
  To: Jakob Koschel
  Cc: Rafael J. Wysocki, Len Brown, ACPI Devel Maling List,
	Linux Kernel Mailing List, Mike Rapoport, Brian Johannesmeyer,
	Cristiano Giuffrida, Bos, H.J.

On Thu, Mar 24, 2022 at 8:04 AM Jakob Koschel <jakobkoschel@gmail.com> wrote:
>
> To move the list iterator variable into the list_for_each_entry_*()
> macro in the future it should be avoided to use the list iterator
> variable after the loop body.
>
> To *never* use the list iterator variable after the loop it was
> concluded to use a separate iterator variable instead of a
> found boolean [1].
>
> This removes the need to use a found variable and simply checking if
> the variable was set, can determine if the break/goto was hit.
>
> Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
> ---
>  drivers/acpi/acpi_ipmi.c | 39 ++++++++++++++++++---------------------
>  1 file changed, 18 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/acpi/acpi_ipmi.c b/drivers/acpi/acpi_ipmi.c
> index a5fe2926bf50..0555f68c2dfd 100644
> --- a/drivers/acpi/acpi_ipmi.c
> +++ b/drivers/acpi/acpi_ipmi.c
> @@ -353,29 +353,27 @@ static void ipmi_flush_tx_msg(struct acpi_ipmi_device *ipmi)
>  static void ipmi_cancel_tx_msg(struct acpi_ipmi_device *ipmi,
>                                struct acpi_ipmi_msg *msg)
>  {
> -       struct acpi_ipmi_msg *tx_msg, *temp;
> -       bool msg_found = false;
> +       struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
>         unsigned long flags;
>
>         spin_lock_irqsave(&ipmi->tx_msg_lock, flags);
> -       list_for_each_entry_safe(tx_msg, temp, &ipmi->tx_msg_list, head) {
> -               if (msg == tx_msg) {
> -                       msg_found = true;
> -                       list_del(&tx_msg->head);
> +       list_for_each_entry_safe(iter, temp, &ipmi->tx_msg_list, head) {
> +               if (msg == iter) {
> +                       tx_msg = iter;
> +                       list_del(&iter->head);
>                         break;
>                 }
>         }
>         spin_unlock_irqrestore(&ipmi->tx_msg_lock, flags);
>
> -       if (msg_found)
> +       if (tx_msg)
>                 acpi_ipmi_msg_put(tx_msg);
>  }
>
>  static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
>  {
>         struct acpi_ipmi_device *ipmi_device = user_msg_data;
> -       bool msg_found = false;
> -       struct acpi_ipmi_msg *tx_msg, *temp;
> +       struct acpi_ipmi_msg *tx_msg = NULL, *iter, *temp;
>         struct device *dev = ipmi_device->dev;
>         unsigned long flags;
>
> @@ -387,16 +385,16 @@ static void ipmi_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
>         }
>
>         spin_lock_irqsave(&ipmi_device->tx_msg_lock, flags);
> -       list_for_each_entry_safe(tx_msg, temp, &ipmi_device->tx_msg_list, head) {
> -               if (msg->msgid == tx_msg->tx_msgid) {
> -                       msg_found = true;
> -                       list_del(&tx_msg->head);
> +       list_for_each_entry_safe(iter, temp, &ipmi_device->tx_msg_list, head) {
> +               if (msg->msgid == iter->tx_msgid) {
> +                       tx_msg = iter;
> +                       list_del(&iter->head);
>                         break;
>                 }
>         }
>         spin_unlock_irqrestore(&ipmi_device->tx_msg_lock, flags);
>
> -       if (!msg_found) {
> +       if (!tx_msg) {
>                 dev_warn(dev,
>                          "Unexpected response (msg id %ld) is returned.\n",
>                          msg->msgid);
> @@ -482,15 +480,14 @@ static void ipmi_register_bmc(int iface, struct device *dev)
>
>  static void ipmi_bmc_gone(int iface)
>  {
> -       struct acpi_ipmi_device *ipmi_device, *temp;
> -       bool dev_found = false;
> +       struct acpi_ipmi_device *ipmi_device = NULL, *iter, *temp;
>
>         mutex_lock(&driver_data.ipmi_lock);
> -       list_for_each_entry_safe(ipmi_device, temp,
> +       list_for_each_entry_safe(iter, temp,
>                                  &driver_data.ipmi_devices, head) {
> -               if (ipmi_device->ipmi_ifnum != iface) {
> -                       dev_found = true;
> -                       __ipmi_dev_kill(ipmi_device);
> +               if (iter->ipmi_ifnum != iface) {
> +                       ipmi_device = iter;
> +                       __ipmi_dev_kill(iter);
>                         break;
>                 }
>         }
> @@ -500,7 +497,7 @@ static void ipmi_bmc_gone(int iface)
>                                         struct acpi_ipmi_device, head);
>         mutex_unlock(&driver_data.ipmi_lock);
>
> -       if (dev_found) {
> +       if (ipmi_device) {
>                 ipmi_flush_tx_msg(ipmi_device);
>                 acpi_ipmi_dev_put(ipmi_device);
>         }
>
> base-commit: f443e374ae131c168a065ea1748feac6b2e76613
> --

Applied as 5.18-rc material, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-25 17:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:04 [PATCH] ACPI: ipmi: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-03-25 17:05 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).