[PATCH v3 12/31] PNP: Attach card devices through the driver core
From: Leon Romanovsky
Date: Wed Nov 18 2026 - 14:33:47 EST
From: Leon Romanovsky <leonro@xxxxxxxxxx>
pnp_request_card_device() calls the PnP bus probe directly, bypassing
the driver core's supplier checks and power management setup. If
device_bind_driver() then fails to create the sysfs links, the device
remains attached and may stay active, but the caller receives NULL and
cannot release it.
Use device_driver_attach() for synchronous probing with the driver
core's setup and error handling. Preserve the card link until binding
completes, so probe cleanup and CONFIG_DEBUG_TEST_DRIVER_REMOVE cannot
clear or free a link still owned by the enclosing card probe.
Fixes: bfc7ee207078 ("[PATCH] PNP: handle sysfs errors")
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxx>
---
drivers/pnp/card.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index df5e3d3cbf6c0..9aaaa03d5ffa9 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -52,13 +52,17 @@ static const struct pnp_card_device_id *match_card(struct pnp_card_driver *drv,
static void card_remove(struct pnp_dev *dev)
{
- dev->card_link = NULL;
+ if (device_is_bound(&dev->dev))
+ dev->card_link = NULL;
}
static void card_remove_first(struct pnp_dev *dev)
{
struct pnp_card_driver *drv = to_pnp_card_driver(dev->driver);
+ /* The card probe still owns its link until this device is bound. */
+ if (!device_is_bound(&dev->dev))
+ return;
if (!dev->card || !drv)
return;
if (drv->remove)
@@ -331,16 +335,12 @@ struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
found:
dev->card_link = clink;
- dev->dev.driver = &drv->link.driver;
- if (pnp_bus_type.probe(&dev->dev))
- goto err_out;
- if (device_bind_driver(&dev->dev))
+ if (device_driver_attach(&drv->link.driver, &dev->dev))
goto err_out;
return dev;
err_out:
- dev->dev.driver = NULL;
dev->card_link = NULL;
return NULL;
}
--
2.56.1