[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 2 Feb 2024 17:25:55 -0500
From: Hamza Mahfooz <hamza.mahfooz@....com>
To: <linux-kernel@...r.kernel.org>
CC: Hamza Mahfooz <hamza.mahfooz@....com>, <stable@...r.kernel.org>, "Greg
Kroah-Hartman" <gregkh@...uxfoundation.org>, "Rafael J. Wysocki"
<rafael@...nel.org>, Alex Deucher <alexander.deucher@....com>,
Christian König <christian.koenig@....com>, "Pan, Xinhui"
<Xinhui.Pan@....com>, David Airlie <airlied@...il.com>, Daniel Vetter
<daniel@...ll.ch>, Bjorn Helgaas <bhelgaas@...gle.com>, Mario Limonciello
<mario.limonciello@....com>, Lijo Lazar <lijo.lazar@....com>, "Srinivasan
Shanmugam" <srinivasan.shanmugam@....com>, Le Ma <le.ma@....com>,
André Almeida <andrealmeid@...lia.com>, James Zhu
<James.Zhu@....com>, Aurabindo Pillai <aurabindo.pillai@....com>, "Jason
Gunthorpe" <jgg@...pe.ca>, Wei Liu <wei.liu@...nel.org>, Robin Murphy
<robin.murphy@....com>, <amd-gfx@...ts.freedesktop.org>,
<dri-devel@...ts.freedesktop.org>, <linux-pci@...r.kernel.org>
Subject: [PATCH 2/3] PCI: introduce can_remove()
Wire up the can_remove() callback, such that pci drivers can implement
their own version of it.
Cc: stable@...r.kernel.org
Signed-off-by: Hamza Mahfooz <hamza.mahfooz@....com>
---
drivers/pci/pci-driver.c | 12 ++++++++++++
include/linux/pci.h | 5 +++++
2 files changed, 17 insertions(+)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 51ec9e7e784f..8aae484c5494 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -466,6 +466,17 @@ static int pci_device_probe(struct device *dev)
return error;
}
+static bool pci_device_can_remove(struct device *dev)
+{
+ struct pci_dev *pci_dev = to_pci_dev(dev);
+ struct pci_driver *drv = pci_dev->driver;
+
+ if (drv->can_remove)
+ return drv->can_remove(pci_dev);
+
+ return true;
+}
+
static void pci_device_remove(struct device *dev)
{
struct pci_dev *pci_dev = to_pci_dev(dev);
@@ -1680,6 +1691,7 @@ struct bus_type pci_bus_type = {
.match = pci_bus_match,
.uevent = pci_uevent,
.probe = pci_device_probe,
+ .can_remove = pci_device_can_remove,
.remove = pci_device_remove,
.shutdown = pci_device_shutdown,
.dev_groups = pci_dev_groups,
diff --git a/include/linux/pci.h b/include/linux/pci.h
index add9368e6314..95276f44b23b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -902,6 +902,10 @@ struct module;
* (negative number) otherwise.
* The probe function always gets called from process
* context, so it can sleep.
+ * @can_remove: The can_remove() function gets called during driver
+ * deregistration to determine if remove() can be called.
+ * The probe function always gets called from process
+ * context, so it can sleep.
* @remove: The remove() function gets called whenever a device
* being handled by this driver is removed (either during
* deregistration of the driver or when it's manually
@@ -943,6 +947,7 @@ struct pci_driver {
const char *name;
const struct pci_device_id *id_table; /* Must be non-NULL for probe to be called */
int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
+ bool (*can_remove)(struct pci_dev *dev);
void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */
int (*resume)(struct pci_dev *dev); /* Device woken up */
--
2.43.0
Powered by blists - more mailing lists