diff mbox series

[v2,resend] bus/vdev: vdev_cleanup checks dev->device.driver

Message ID 20221019140801.1700392-1-zhangfei.gao@linaro.org
State New
Headers show
Series [v2,resend] bus/vdev: vdev_cleanup checks dev->device.driver | expand

Commit Message

Zhangfei Gao Oct. 19, 2022, 2:08 p.m. UTC
vdev_probe calls driver->probe and set dev->device.driver,
which will be NULL if the probe fails.

In vdev_cleanup, drv = container_of(dev->device.driver)
drv will be !NULL in this case, causing drv->remove
Segmentation fault.

Fixed by checking dev->device.driver before.

Log:
$ sudo dpdk-test --vdev=crypto_uadk --log-level=6
vdev_probe(): failed to initialize crypto_uadk device
EAL: Bus (vdev) probe failed.
RTE>>quit
Segmentation fault

Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
---
v2: 
Suggested by David Marchand <david.marchand@redhat.com>
1. Add Fixes
2. "If dev->device.driver != NULL, then drv won't be NULL", so remove it

 drivers/bus/vdev/vdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

David Marchand Oct. 20, 2022, 11:32 a.m. UTC | #1
On Wed, Oct 19, 2022 at 4:14 PM Zhangfei Gao <zhangfei.gao@linaro.org> wrote:
>
> vdev_probe calls driver->probe and set dev->device.driver,
> which will be NULL if the probe fails.
>
> In vdev_cleanup, drv = container_of(dev->device.driver)
> drv will be !NULL in this case, causing drv->remove
> Segmentation fault.
>
> Fixed by checking dev->device.driver before.
>
> Log:
> $ sudo dpdk-test --vdev=crypto_uadk --log-level=6
> vdev_probe(): failed to initialize crypto_uadk device
> EAL: Bus (vdev) probe failed.
> RTE>>quit
> Segmentation fault
>
> Fixes: 1cab1a40ea9b ("bus: cleanup devices on shutdown")

> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>

Reviewed-by: David Marchand <david.marchand@redhat.com>

Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index f5b43f1930..41bc07dde7 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -577,9 +577,12 @@  vdev_cleanup(void)
 		const struct rte_vdev_driver *drv;
 		int ret = 0;
 
+		if (dev->device.driver == NULL)
+			continue;
+
 		drv = container_of(dev->device.driver, const struct rte_vdev_driver, driver);
 
-		if (drv == NULL || drv->remove == NULL)
+		if (drv->remove == NULL)
 			continue;
 
 		ret = drv->remove(dev);