Linux-ACPI Archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	acpica-devel@lists.linux.dev
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>,
	Robert Moore <robert.moore@intel.com>
Subject: [PATCH v1 3/7] ACPI: scan: Replace infinite for-loop with finite while-loop
Date: Mon, 25 Mar 2024 14:32:59 +0200	[thread overview]
Message-ID: <20240325123444.3031851-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20240325123444.3031851-1-andriy.shevchenko@linux.intel.com>

The infinite loops is harder to understand (as one has to go
over the body in order to find main exit conditional) and it's
more verbose than usual approach with a while-loop.

Note, we may not use list_for_each_entry_safe() as there is locking
involved and the saved pointer may become invalid behind our back.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/scan.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 7c157bf92695..5e4118970285 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -530,15 +530,10 @@ static DEFINE_MUTEX(acpi_device_del_lock);
 
 static void acpi_device_del_work_fn(struct work_struct *work_not_used)
 {
-	for (;;) {
-		struct acpi_device *adev;
+	struct acpi_device *adev;
 
-		mutex_lock(&acpi_device_del_lock);
-
-		if (list_empty(&acpi_device_del_list)) {
-			mutex_unlock(&acpi_device_del_lock);
-			break;
-		}
+	mutex_lock(&acpi_device_del_lock);
+	while (!list_empty(&acpi_device_del_list)) {
 		adev = list_first_entry(&acpi_device_del_list,
 					struct acpi_device, del_list);
 		list_del(&adev->del_list);
@@ -555,7 +550,10 @@ static void acpi_device_del_work_fn(struct work_struct *work_not_used)
 		 */
 		acpi_power_transition(adev, ACPI_STATE_D3_COLD);
 		acpi_dev_put(adev);
+
+		mutex_lock(&acpi_device_del_lock);
 	}
+	mutex_unlock(&acpi_device_del_lock);
 }
 
 /**
-- 
2.43.0.rc1.1.gbec44491f096


  parent reply	other threads:[~2024-03-25 12:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 12:32 [PATCH v1 0/7] ACPI: scan: A few ad-hoc cleanups Andy Shevchenko
2024-03-25 12:32 ` [PATCH v1 1/7] ACPI: bus: Make container_of() no-op where it makes sense Andy Shevchenko
2024-03-25 12:32 ` [PATCH v1 2/7] ACPI: bus: Don't use "proxy" headers Andy Shevchenko
2024-03-25 12:32 ` Andy Shevchenko [this message]
2024-04-04 19:22   ` [PATCH v1 3/7] ACPI: scan: Replace infinite for-loop with finite while-loop Rafael J. Wysocki
2024-04-04 19:26     ` Andy Shevchenko
2024-03-25 12:33 ` [PATCH v1 4/7] ACPI: scan: Use list_first_entry_or_null() in acpi_device_hid() Andy Shevchenko
2024-03-25 12:33 ` [PATCH v1 5/7] ACPI: scan: Move misleading comment to acpi_dma_configure_id() Andy Shevchenko
2024-03-25 12:33 ` [PATCH v1 6/7] ACPI: scan: Use standard error checking pattern Andy Shevchenko
2024-03-25 12:33 ` [PATCH v1 7/7] ACPI: scan: Introduce typedef:s for struct acpi_hotplug_context members Andy Shevchenko
2024-03-27  5:50 ` [PATCH v1 0/7] ACPI: scan: A few ad-hoc cleanups Kuppuswamy Sathyanarayanan

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=20240325123444.3031851-4-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=acpica-devel@lists.linux.dev \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=robert.moore@intel.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).