Skip to contentSkip to conversation

ACPI: support ejecting device in userspace

PATCH In review Zhang Rui 1 participant 1 message Jan 17, 2008 ACPI

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

PATCH 4/4 ACPI: support ejecting device in userspace

From: Zhang Rui <[email protected]>

"/sys/devices/LNXSYSTM:00/.../eject" is used to evaluate _EJx method and eject a device in user space.
But "echo 1 > eject" causes deadlock because
the device hot-removal code will try to remove the "eject" file as a result. Queues the hot-removal function for deferred execution in this patch.
http://bugzilla.kernel.org/show_bug.cgi?id=9731

---
 drivers/acpi/scan.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/acpi/scan.c +6 -12
Index: linux-2.6/drivers/acpi/scan.c
===================================================================
@@ -151,15 +151,13 @@ acpi_bus_eject_device(acpi_handle handle
 	return 0;
 }
 
+void acpi_bus_hot_remove_device(void *context);
 static ssize_t
 acpi_eject_store(struct device *d, struct device_attribute *attr,
 		const char *buf, size_t count)
 {
-	int result;
 	int ret = count;
-	int islockable;
 	acpi_status status;
-	acpi_handle handle;
 	acpi_object_type type = 0;
 	struct acpi_device *acpi_device = to_acpi_device(d);
 
@@ -178,17 +176,13 @@ acpi_eject_store(struct device *d, struc
 		goto err;
 	}
 
-	islockable = acpi_device->flags.lockable;
-	handle = acpi_device->handle;
+	status = acpi_os_execute(OSL_DEVICE_HOTPLUG_HANDLER,
+				 acpi_bus_hot_remove_device,
+				 acpi_device->handle);
 
-	result = acpi_bus_trim(acpi_device, 1);
-
-	if (!result)
-		result = acpi_bus_eject_device(handle, islockable);
+	if (status)
+		ret = -ENODEV;
 
-	if (result) {
-		ret = -EBUSY;
-	}
       err:
 	return ret;
 }