[2/2] bus/vdev: fix a segfault when call callback
Checks
Commit Message
From: Huisong Li <lihuisong@huawei.com>
After the driver probe is executed, the callback in application will be
called. And this callback may call some APIs which access the driver in
struct rte_vdev_driver by the device::driver pointer to get some driver
information. If the rte_vdev_device::device::driver pointer isn't pointed
to the rte_vdev_driver::driver before executing driver probe, a segfault
will occur.
Fixes: e9d159c3d534 ("eal: allow probing a device again")
Cc: stable@dpdk.org
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
drivers/bus/vdev/vdev.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
@@ -209,9 +209,16 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
return -1;
}
+ /*
+ * After the driver probe is executed, the callback in application will
+ * be called. The callback in application may call some APIs which use
+ * dev->device.driver to get some driver information. If the driver
+ * pointer isn't pointed to driver->driver here, a segfault will occur.
+ */
+ dev->device.driver = &driver->driver;
ret = driver->probe(dev);
- if (ret == 0)
- dev->device.driver = &driver->driver;
+ if (ret != 0)
+ dev->device.driver = NULL;
return ret;
}