dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] driver core: bus: introduce can_remove()
@ 2024-02-02 22:25 Hamza Mahfooz
  2024-02-02 22:25 ` [PATCH 2/3] PCI: " Hamza Mahfooz
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Hamza Mahfooz @ 2024-02-02 22:25 UTC (permalink / raw)
  To: linux-kernel
  Cc: Hamza Mahfooz, stable, Greg Kroah-Hartman, Rafael J. Wysocki,
	Alex Deucher, Christian König, Pan, Xinhui, David Airlie,
	Daniel Vetter, Bjorn Helgaas, Mario Limonciello, Lijo Lazar,
	Srinivasan Shanmugam, Le Ma, André Almeida, James Zhu,
	Aurabindo Pillai, Joerg Roedel, Iwona Winiarska, Robin Murphy,
	amd-gfx, dri-devel, linux-pci

Currently, drivers have no mechanism to block requests to unbind
devices. However, this can cause resource leaks and leave the device in
an inconsistent state, such that rebinding the device may cause a hang
or otherwise prevent the device from being rebound. So, introduce
the can_remove() callback to allow drivers to indicate if it isn't
appropriate to remove a device at the given time.

Cc: stable@vger.kernel.org
Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com>
---
 drivers/base/bus.c         | 4 ++++
 include/linux/device/bus.h | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index daee55c9b2d9..7c259b01ea99 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -239,6 +239,10 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
 	if (dev && dev->driver == drv) {
+		if (dev->bus && dev->bus->can_remove &&
+		    !dev->bus->can_remove(dev))
+			return -EBUSY;
+
 		device_driver_detach(dev);
 		err = count;
 	}
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index 5ef4ec1c36c3..c9d4af0ed3b8 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -46,6 +46,7 @@ struct fwnode_handle;
  *		be called at late_initcall_sync level. If the device has
  *		consumers that are never bound to a driver, this function
  *		will never get called until they do.
+ * @can_remove: Called before attempting to remove a device from this bus.
  * @remove:	Called when a device removed from this bus.
  * @shutdown:	Called at shut-down time to quiesce the device.
  *
@@ -85,6 +86,7 @@ struct bus_type {
 	int (*uevent)(const struct device *dev, struct kobj_uevent_env *env);
 	int (*probe)(struct device *dev);
 	void (*sync_state)(struct device *dev);
+	bool (*can_remove)(struct device *dev);
 	void (*remove)(struct device *dev);
 	void (*shutdown)(struct device *dev);
 
-- 
2.43.0


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

end of thread, other threads:[~2024-02-09 11:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-02 22:25 [PATCH 1/3] driver core: bus: introduce can_remove() Hamza Mahfooz
2024-02-02 22:25 ` [PATCH 2/3] PCI: " Hamza Mahfooz
2024-02-02 23:38   ` Greg Kroah-Hartman
2024-02-02 22:25 ` [PATCH 3/3] drm/amdgpu: wire up the can_remove() callback Hamza Mahfooz
2024-02-02 22:41   ` Bjorn Helgaas
2024-02-02 23:40   ` Greg Kroah-Hartman
2024-02-06 14:29     ` Daniel Vetter
2024-02-06 18:42       ` Christian König
2024-02-09 11:00         ` Daniel Vetter
2024-02-02 23:41   ` Greg Kroah-Hartman
2024-02-02 23:38 ` [PATCH 1/3] driver core: bus: introduce can_remove() Greg Kroah-Hartman
2024-02-05  8:48 ` Christian König

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).