[RFC PATCH v2 3/6] vfio-platform: Move region initialization to vfio_platform_init_common

Eric Auger posted 6 patches 2 months, 1 week ago
[RFC PATCH v2 3/6] vfio-platform: Move region initialization to vfio_platform_init_common
Posted by Eric Auger 2 months, 1 week ago
We plan to introduce a new reset module init() callback. This latter
would need to have vdev->regions populated. At the moment this latter
is allocated and populated later on device open.

Call vfio_platform_regions_init() in vfio_platform_init_common()
instead.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 drivers/vfio/platform/vfio_platform_common.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index 976864d2e2f0..cd0f2ebff586 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -243,7 +243,6 @@ void vfio_platform_close_device(struct vfio_device *core_vdev)
 			ret, extra_dbg ? extra_dbg : "");
 	}
 	pm_runtime_put(vdev->device);
-	vfio_platform_regions_cleanup(vdev);
 	vfio_platform_irq_cleanup(vdev);
 }
 EXPORT_SYMBOL_GPL(vfio_platform_close_device);
@@ -255,13 +254,9 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
 	const char *extra_dbg = NULL;
 	int ret;
 
-	ret = vfio_platform_regions_init(vdev);
-	if (ret)
-		return ret;
-
 	ret = vfio_platform_irq_init(vdev);
 	if (ret)
-		goto err_irq;
+		return ret;
 
 	ret = pm_runtime_get_sync(vdev->device);
 	if (ret < 0)
@@ -280,8 +275,6 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
 err_rst:
 	pm_runtime_put(vdev->device);
 	vfio_platform_irq_cleanup(vdev);
-err_irq:
-	vfio_platform_regions_cleanup(vdev);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(vfio_platform_open_device);
@@ -658,12 +651,17 @@ int vfio_platform_init_common(struct vfio_platform_device *vdev)
 		return ret;
 
 	vdev->device = dev;
+	ret = vfio_platform_regions_init(vdev);
+	if (ret)
+		return ret;
+
 	mutex_init(&vdev->igate);
 
 	ret = vfio_platform_get_reset(vdev);
 	if (ret && vdev->reset_required) {
 		dev_err(dev, "No reset function found for device %s\n",
 			vdev->name);
+		vfio_platform_regions_cleanup(vdev);
 		return ret;
 	}
 
@@ -674,6 +672,7 @@ EXPORT_SYMBOL_GPL(vfio_platform_init_common);
 void vfio_platform_release_common(struct vfio_platform_device *vdev)
 {
 	vfio_platform_put_reset(vdev);
+	vfio_platform_regions_cleanup(vdev);
 }
 EXPORT_SYMBOL_GPL(vfio_platform_release_common);
 
-- 
2.41.0