RDMA/i40iw: Fix device initialization error path
authorMustafa Ismail <mustafa.ismail@intel.com>
Thu, 11 May 2017 04:32:14 +0000 (23:32 -0500)
committerDoug Ledford <dledford@redhat.com>
Thu, 1 Jun 2017 20:59:46 +0000 (16:59 -0400)
Some error paths in i40iw_initialize_dev are doing
additional and unnecessary work before exiting.
Correctly free resources allocated prior to error
and return with correct status code.

Signed-off-by: Mustafa Ismail <mustafa.ismail@intelcom>
Signed-off-by: Henry Orosco <henry.orosco@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/i40iw/i40iw_main.c

index 2728af3103ce9ae285ab8c0b88980e716a1cb5e4..a3f18a22f5ed1787794031eb8a1765ab2804cdc4 100644 (file)
@@ -1319,13 +1319,13 @@ static enum i40iw_status_code i40iw_initialize_dev(struct i40iw_device *iwdev,
        status = i40iw_obj_aligned_mem(iwdev, &mem, I40IW_QUERY_FPM_BUF_SIZE,
                                       I40IW_FPM_QUERY_BUF_ALIGNMENT_MASK);
        if (status)
-               goto exit;
+               goto error;
        info.fpm_query_buf_pa = mem.pa;
        info.fpm_query_buf = mem.va;
        status = i40iw_obj_aligned_mem(iwdev, &mem, I40IW_COMMIT_FPM_BUF_SIZE,
                                       I40IW_FPM_COMMIT_BUF_ALIGNMENT_MASK);
        if (status)
-               goto exit;
+               goto error;
        info.fpm_commit_buf_pa = mem.pa;
        info.fpm_commit_buf = mem.va;
        info.hmc_fn_id = ldev->fid;
@@ -1347,11 +1347,9 @@ static enum i40iw_status_code i40iw_initialize_dev(struct i40iw_device *iwdev,
        info.exception_lan_queue = 1;
        info.vchnl_send = i40iw_virtchnl_send;
        status = i40iw_device_init(&iwdev->sc_dev, &info);
-exit:
-       if (status) {
-               kfree(iwdev->hmc_info_mem);
-               iwdev->hmc_info_mem = NULL;
-       }
+
+       if (status)
+               goto error;
        memset(&vsi_info, 0, sizeof(vsi_info));
        vsi_info.dev = &iwdev->sc_dev;
        vsi_info.back_vsi = (void *)iwdev;
@@ -1362,11 +1360,19 @@ exit:
                memset(&stats_info, 0, sizeof(stats_info));
                stats_info.fcn_id = ldev->fid;
                stats_info.pestat = kzalloc(sizeof(*stats_info.pestat), GFP_KERNEL);
+               if (!stats_info.pestat) {
+                       status = I40IW_ERR_NO_MEMORY;
+                       goto error;
+               }
                stats_info.stats_initialize = true;
                if (stats_info.pestat)
                        i40iw_vsi_stats_init(&iwdev->vsi, &stats_info);
        }
        return status;
+error:
+       kfree(iwdev->hmc_info_mem);
+       iwdev->hmc_info_mem = NULL;
+       return status;
 }
 
 /**