PNP: Detach device after resource transition failure
Subsystems (2)
PATCH 1/1 PNP: Detach device after resource transition failure
pnp_device_probe() attaches the PNP device before it activates or disables its resources. The attach changes the status from PNP_READY to PNP_ATTACHED, but errors from either resource transition return directly and leave that status behind. A later bind or manual PNP configuration attempt then sees a device that is still marked in use.
Route both errors through the existing failure path so it restores the status to PNP_READY. Do not disable the device or clean its resources:pnp_activate_dev() only marks it active after a successful start, while pnp_disable_dev() preserves the active state and resource table when stopping fails.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/pnp/driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pnp/driver.c +2 -2
@@ -96,13 +96,13 @@ static int pnp_device_probe(struct device *dev)if (!(pnp_drv->flags &PNP_DRIVER_RES_DO_NOT_CHANGE )) { error =pnp_activate_dev (pnp_dev);if (error <0 ) -return error; + goto fail; } }else if ((pnp_drv->flags &PNP_DRIVER_RES_DISABLE ) ==PNP_DRIVER_RES_DISABLE ) { error =pnp_disable_dev (pnp_dev);if (error <0 ) -return error; + goto fail; } error =0 ;if (pnp_drv->probe) {
Signature · 1 line
2.50.1
Quoted 34 lines · Myeonghun Pak
pnp_device_probe()attaches the PNP device before it activates or disables its resources. The attach changes the status fromPNP_READYtoPNP_ATTACHED, but errors from either resource transition return directly and leave that status behind. A later bind or manual PNP configuration attempt then sees a device that is still marked in use.Route both errors through the existing failure path so it restores the status to
PNP_READY. Do not disable the device or clean its resources:pnp_activate_dev()only marks it active after a successful start, whilepnp_disable_dev()preserves the active state and resource table when stopping fails.This issue was identified during our ongoing static-analysis research while reviewing kernel code.
Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>--- drivers/pnp/driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pnp/driver.c +1
-1@@ -96,13 +96,13 @@ static int pnp_device_probe(struct device *dev)if (!(pnp_drv->flags &PNP_DRIVER_RES_DO_NOT_CHANGE )) { error =pnp_activate_dev (pnp_dev);if (error <0 ) -return error; + goto fail; }
drivers/pnp/driver.c static int pnp_device_probe(struct device *dev)
Quoted 10 lines
drivers/pnp/driver.c +1
-2}else if ((pnp_drv->flags &PNP_DRIVER_RES_DISABLE ) ==PNP_DRIVER_RES_DISABLE ) { error =pnp_disable_dev (pnp_dev);if (error <0 ) -return error; + goto fail; } error =0 ;if (pnp_drv->probe) { --
Applied as 7.4 material, thanks!