mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: ACPI Devel Maling List <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>, Jiang Liu <liuj97@gmail.com>,
	Yinghai Lu <yinghai@kernel.org>,
	"Alexander E. Patrakov" <patrakov@gmail.com>
Subject: [PATCH 3/4] ACPI / dock: Walk list in reverse order during removal of devices
Date: Fri, 28 Jun 2013 21:47:06 +0200	[thread overview]
Message-ID: <2531931.mBTduI0HDx@vostro.rjw.lan> (raw)
In-Reply-To: <1640211.P0jyS5muX2@vostro.rjw.lan>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If there are indirect dependencies between devices in a dock
station's dependent devices list, they may be broken if the devices
are removed in the same order in which they have been added.

For this reason, make the code in handle_eject_request() walk the
list of dependent devices in reverse order.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/dock.c |   45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

Index: linux-pm/drivers/acpi/dock.c
===================================================================
--- linux-pm.orig/drivers/acpi/dock.c
+++ linux-pm/drivers/acpi/dock.c
@@ -396,9 +396,29 @@ static void dock_remove_acpi_device(acpi
 }
 
 /**
- * hotplug_dock_devices - insert or remove devices on the dock station
+ * hot_remove_dock_devices - Remove dock station devices.
+ * @ds: Dock station.
+ */
+static void hot_remove_dock_devices(struct dock_station *ds)
+{
+	struct dock_dependent_device *dd;
+
+	/*
+	 * Walk the list in reverse order so that devices that have been added
+	 * last are removed first (in case there are some indirect dependencies
+	 * between them).
+	 */
+	list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
+		dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false);
+
+	list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
+		dock_remove_acpi_device(dd->handle);
+}
+
+/**
+ * hotplug_dock_devices - Insert devices on a dock station.
  * @ds: the dock station
- * @event: either bus check or eject request
+ * @event: either bus check or device check request
  *
  * Some devices on the dock station need to have drivers called
  * to perform hotplug operations after a dock event has occurred.
@@ -409,24 +429,17 @@ static void hotplug_dock_devices(struct
 {
 	struct dock_dependent_device *dd;
 
-	/*
-	 * First call driver specific hotplug functions
-	 */
+	/* Call driver specific hotplug functions. */
 	list_for_each_entry(dd, &ds->dependent_devices, list)
 		dock_hotplug_event(dd, event, false);
 
 	/*
-	 * Now make sure that an acpi_device is created for each
-	 * dependent device, or removed if this is an eject request.
-	 * This will cause acpi_drivers to be stopped/started if they
-	 * exist
+	 * Now make sure that an acpi_device is created for each dependent
+	 * device.  That will cause scan handlers to be attached to device
+	 * objects or acpi_drivers to be stopped/started if they are present.
 	 */
-	list_for_each_entry(dd, &ds->dependent_devices, list) {
-		if (event == ACPI_NOTIFY_EJECT_REQUEST)
-			dock_remove_acpi_device(dd->handle);
-		else
-			dock_create_acpi_device(dd->handle);
-	}
+	list_for_each_entry(dd, &ds->dependent_devices, list)
+		dock_create_acpi_device(dd->handle);
 }
 
 static void dock_event(struct dock_station *ds, u32 event, int num)
@@ -699,7 +712,7 @@ static int handle_eject_request(struct d
 	 */
 	dock_event(ds, event, UNDOCK_EVENT);
 
-	hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
+	hot_remove_dock_devices(ds);
 	undock(ds);
 	dock_lock(ds, 0);
 	eject_dock(ds);


  parent reply	other threads:[~2013-06-28 19:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-28 19:44 [PATCH 0/4] ACPI / dock: Cleanups and simplifications Rafael J. Wysocki
2013-06-28 19:45 ` [PATCH 1/4] ACPI / dock: Drop the hp_lock mutex from struct dock_station Rafael J. Wysocki
2013-06-28 19:46 ` [PATCH 2/4] ACPI / dock: Rework and simplify find_dock_devices() Rafael J. Wysocki
2013-06-28 20:08   ` Yinghai Lu
2013-06-28 19:47 ` Rafael J. Wysocki [this message]
2013-06-28 20:14   ` [PATCH 3/4] ACPI / dock: Walk list in reverse order during removal of devices Yinghai Lu
2013-06-28 19:48 ` [PATCH 4/4] ACPI / dock: Simplify dock_init_hotplug() and dock_release_hotplug() Rafael J. Wysocki
2013-06-28 20:16   ` Yinghai Lu
2013-06-28 22:47 ` [PATCH 0/3] ACPI / dock: Notification rework and memory leak fix Rafael J. Wysocki
2013-06-28 22:53   ` [PATCH 1/3] ACPI / dock: Rework the handling of notifications Rafael J. Wysocki
2013-06-28 23:34     ` Yinghai Lu
2013-06-29 11:16       ` Rafael J. Wysocki
2013-06-29 16:12         ` Yinghai Lu
2013-06-30 14:18           ` Rafael J. Wysocki
2013-07-01 20:21     ` Bjorn Helgaas
2013-07-02  1:28       ` Rafael J. Wysocki
2013-06-28 22:54   ` [PATCH 2/3] ACPI: Drop ACPI bus notifier call chain Rafael J. Wysocki
2013-06-28 22:54   ` [PATCH 3/3] ACPI / dock: Do not leak memory on falilures to add a dock station Rafael J. Wysocki
2013-07-03 23:23   ` [PATCH 0/4] ACPI / dock: One fix and more cleanups Rafael J. Wysocki
2013-07-03 23:25     ` [PATCH 1/4] ACPI / dock: Actually define acpi_dock_init() as void Rafael J. Wysocki
2013-07-03 23:26     ` [PATCH 2/4] ACPI / dock: Do not check CONFIG_ACPI_DOCK_MODULE Rafael J. Wysocki
2013-07-03 23:27     ` [PATCH 3/4] ACPI / dock / PCI: Drop ACPI dock notifier chain Rafael J. Wysocki
2013-07-03 23:28     ` [PATCH 4/4] ACPI / dock: Drop unnecessary local variable from dock_add() Rafael J. Wysocki

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=2531931.mBTduI0HDx@vostro.rjw.lan \
    --to=rjw@sisk.pl \
    --cc=bhelgaas@google.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=patrakov@gmail.com \
    --cc=yinghai@kernel.org \
    /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®