Currently, when we map the MC portal object, we call into VFIO device
setup to get a device fd, but we do not check whether that succeeded. If
device setup fails before a device fd was obtained (for example, when
the group fd cannot be found), the fd variable is left uninitialized, and
we go on to issue a region info ioctl on it and then close it.

Fix it by checking the return value and bailing out early.

Fixes: a69f79300262 ("bus/fslmc: support multi VFIO group")
Cc: [email protected]
Cc: [email protected]

Signed-off-by: Anatoly Burakov <[email protected]>
---
 drivers/bus/fslmc/fslmc_vfio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index 5ffa869e6fc..e8c6948bebb 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -1322,7 +1322,9 @@ static intptr_t vfio_map_mcp_obj(const char *mcp_obj)
        struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
        struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
 
-       fslmc_vfio_setup_device(mcp_obj, &mc_fd, &d_info);
+       ret = fslmc_vfio_setup_device(mcp_obj, &mc_fd, &d_info);
+       if (ret != 0)
+               return v_addr;
 
        /* getting device region info*/
        ret = ioctl(mc_fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info);
-- 
2.52.0

Reply via email to