[ofw] prefast-caused patches

Smith, Stan stan.smith at intel.com
Tue Dec 13 06:11:03 PST 2011


Thanks Leonid, I'll apply these to branches\mlx4_full so they do not get lost in a future merge.

Stan.

From: Leonid Keller [mailto:leonid at mellanox.com]
Sent: Tuesday, December 13, 2011 1:27 AM
To: Smith, Stan
Cc: ofw_list
Subject: prefast-caused patches

Hi Stan,

We've checked our version of WinOF stack with Prefast and made some changes on base of its warnings.
I'm not sure they can be automatically put on the WinOfed tree, but may be you'll find some of them interesting and important and worth to be taken.
For example, one for libibverbs/src/device.cpp (see below).
It's just a bug, albeit a minor one.

Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winmad/kernel/wm_reg.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winmad/kernel/wm_reg.c                (revision 9121)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winmad/kernel/wm_reg.c             (revision 9122)
@@ -125,6 +125,7 @@
                ib_status = dev->IbInterface.open_ca(pRegistration->hIbal, pAttributes->Guid,
                                                                                                                                                                 NULL, NULL, &pRegistration->hCa);
                if (ib_status != IB_SUCCESS) {
+        status = STATUS_UNSUCCESSFUL;
                                goto err2;
                }
                DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL,"REF_CNT_DBG: WM open_ca %p\n", pRegistration->hCa);
@@ -132,6 +133,7 @@
                ib_status = dev->IbInterface.alloc_pd(pRegistration->hCa, IB_PDT_ALIAS,
                                                                                                                                                                  NULL, &pRegistration->hPd);
                if (ib_status != IB_SUCCESS) {
+        status = STATUS_UNSUCCESSFUL;
                                goto err3;
                }

Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winverbs/kernel/wv_pd.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winverbs/kernel/wv_pd.c (revision 9121)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winverbs/kernel/wv_pd.c              (revision 9122)
@@ -421,6 +421,7 @@
                                goto err1;
                }

+    #pragma prefast(suppress:28197, "The memory is freed on WvMwDeallocate function");
                mw = ExAllocatePoolWithTag(PagedPool, sizeof(WV_MEMORY_WINDOW), 'wmvw');
                if (mw == NULL) {
                                status = STATUS_NO_MEMORY;
@@ -550,7 +551,7 @@
                                goto err1;
                }

-              #pragma prefast(suppress:18197, "The memory is freed on WvAhFree function");
+             #pragma prefast(suppress:28197, "The memory is freed on WvAhFree function");
                ah = ExAllocatePoolWithTag(PagedPool, sizeof(WV_ADDRESS_HANDLE), 'havw');
                if (ah == NULL) {
                                status = STATUS_NO_MEMORY;
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/kernel/al_cm.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/kernel/al_cm.c  (revision 9121)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/kernel/al_cm.c               (revision 9122)
@@ -48,6 +48,7 @@
 {
                iba_cm_id_priv *id;

+    #pragma prefast(suppress: 6014, "The allocated memory is freed in function cm_free_id.");
                id = ExAllocatePoolWithTag(NonPagedPool, sizeof(iba_cm_id_priv), 'mcbi');
                if (id == NULL) {
                                return NULL;
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/cmd.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/cmd.c                (revision 9121)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/cmd.c             (revision 9122)
@@ -425,7 +425,7 @@
     vhcr->err = 0;
     ret = mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_POST, 0, MLX4_COMM_TIME + timeout);
     if (!ret) {
-        if (out_is_imm)
+        if (out_is_imm && out_param != NULL)
             *out_param = vhcr->out_param;
         ret = vhcr->err;
     }
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/eq.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/eq.c   (revision 9121)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/eq.c                (revision 9122)
@@ -572,7 +572,7 @@

                                case MLX4_EVENT_TYPE_PPF_REMOVE:
                                                if (mlx4_is_slave(dev)) {
-                                                              int i = 0;
+                i = 0;
                                                                if (dev->pdev->ib_dev) {
                                                                                dev->flags |= MLX4_FLAG_RESET_4_RMV;         // bar the device
                                                                                i = mlx4_dispatch_reset_event(dev->pdev->ib_dev, IB_EVENT_RESET_4_RMV);
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/mr.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/mr.c   (revision 9121)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/mr.c                (revision 9122)
@@ -789,7 +789,7 @@
                                return -EINVAL;

                /* Trust the user not to pass misaligned data in page_list */
-              if (!fmr) /* instead of 0, that is warned by compiler */
+             if (fmr == NULL) /* instead of 0, that is warned by compiler */
                                for (i = 0; i < npages; ++i) {
                                                if (page_list[i] & ~page_mask)
                                                                return -EINVAL;


Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/ulp/libibverbs/src/device.cpp
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/ulp/libibverbs/src/device.cpp     (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/ulp/libibverbs/src/device.cpp  (revision 9350)
@@ -184,12 +184,13 @@
                if (num != NULL) {
                                *num = (int) size;
                }
+        delete [] guid;
                return pdev_array;

 err3:
                ibv_free_device_list(pdev_array);
 err2:
-              delete guid;
+             delete [] guid;
 err1:
                return NULL;
 }
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/tests/cmtest/user/cmtest_main.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/tests/cmtest/user/cmtest_main.c            (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/tests/cmtest/user/cmtest_main.c         (revision 9350)
@@ -994,7 +994,7 @@
 {
                uint64_t                               start_time, total_time;
                int32_t                                  i;
-              ib_api_status_t                status;
+             ib_api_status_t                status = IB_SUCCESS;

                printf( "Creating QPs...\n" );
                start_time = cl_get_time_stamp();
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winverbs/kernel/wv_ep.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winverbs/kernel/wv_ep.c (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/winverbs/kernel/wv_ep.c              (revision 9350)
@@ -479,6 +479,7 @@
                                WDF_REQUEST_PARAMETERS_INIT(&param);
                                WdfRequestGetParameters(request, &param);
                                if (param.Parameters.DeviceIoControl.IoControlCode == WV_IOCTL_EP_DISCONNECT) {
+            ASSERT(pEndpoint->pWork != NULL);
                                                WdfRequestSetInformation(request, DiscStatus);
                                                WvProviderGet(pEndpoint->pProvider);
                                                WorkQueueInsert(&pEndpoint->pProvider->WorkQueue, &pEndpoint->pWork->Work);
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_srq.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_srq.c (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_srq.c              (revision 9350)
@@ -214,8 +214,9 @@
                IN           OUT                                       ci_umv_buf_t* const                                     p_umv_buf )
 {
                ib_api_status_t                                                status;
-
+
                AL_ENTER( AL_DBG_SRQ );
+             ASSERT(h_srq != NULL);

                if( AL_OBJ_INVALID_HANDLE( h_srq, AL_OBJ_TYPE_H_SRQ ) )
                {
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_mgr_shared.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_mgr_shared.c               (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_mgr_shared.c            (revision 9350)
@@ -310,6 +310,7 @@
                                                goto end;

                                /* Try to match the GID with one of the port's GIDs. */
+        ASSERT(p_ca_attr != NULL);
                                status = IB_NOT_FOUND;
                                for( port_ind = 0; port_ind < p_ca_attr->num_ports; port_ind++ )
                                {
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/catas.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/catas.c              (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/catas.c           (revision 9350)
@@ -139,7 +139,7 @@
                IN                                                           PVOID                                                                                   context)
 {

-
+    ASSERT(context != NULL);
                struct mlx4_dev * dev = (struct mlx4_dev *) context;
                UNUSED_PARAM(p_dev_obj);

@@ -404,6 +404,7 @@
                IN                                                           PDEVICE_OBJECT                                                             p_dev_obj,
     IN                                                      PVOID                                                                                   context)
 {
+    ASSERT(context != NULL);
                struct ib_event_handler *           event_handler = (struct ib_event_handler *) context;
                struct ib_device *ibdev = event_handler->device;

Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/core/cache.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/core/cache.c           (revision 9349)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/core/cache.c        (revision 9350)
@@ -334,7 +334,8 @@
                IN PDEVICE_OBJECT  DeviceObject,
                IN PVOID  Context
                )
-{
+{
+    ASSERT(Context != NULL);
                struct ib_update_work *work = (struct ib_update_work *)Context;
                UNREFERENCED_PARAMETER(DeviceObject);
                ib_cache_task(Context);

Index: mr.c
===================================================================
--- mr.c (revision 9350)
+++ mr.c              (revision 9351)
@@ -779,6 +779,8 @@
 {             int i, page_mask;

 +    ASSERT(fmr != NULL);

                if (npages > fmr->max_pages)
                                return -EINVAL;

@@ -788,13 +790,6 @@
                if (iova & page_mask)
                                return -EINVAL;

 -             /* Trust the user not to pass misaligned data in page_list */
 -             if (fmr == NULL) /* instead of 0, that is warned by compiler */
 -                             for (i = 0; i < npages; ++i) {
 -                                             if (page_list[i] & ~page_mask)-                                                 return -EINVAL;
 -                             }
 -
                if (fmr->maps >= fmr->max_maps)
                                return -EINVAL;

Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_srq.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_srq.c (revision 9352)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_srq.c              (revision 9353)
@@ -216,7 +216,7 @@
                ib_api_status_t                                                status;

                AL_ENTER( AL_DBG_SRQ );
-              ASSERT(h_srq != NULL);
+             CL_ASSERT(h_srq != NULL);

                if( AL_OBJ_INVALID_HANDLE( h_srq, AL_OBJ_TYPE_H_SRQ ) )
                {
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_mgr_shared.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_mgr_shared.c               (revision 9352)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/core/al/al_mgr_shared.c            (revision 9353)
@@ -310,7 +310,7 @@
                                                goto end;

                                /* Try to match the GID with one of the port's GIDs. */
-        ASSERT(p_ca_attr != NULL);
+        CL_ASSERT(p_ca_attr != NULL);
                                status = IB_NOT_FOUND;
                                for( port_ind = 0; port_ind < p_ca_attr->num_ports; port_ind++ )
                                {
Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/etc/user/gtod.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/etc/user/gtod.c (revision 9352)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/etc/user/gtod.c              (revision 9353)
@@ -42,8 +42,10 @@
                LONGLONG ll;

                if(!pft || !ptv) {
-                              ptv->tv_sec = 0;
-                              ptv->tv_usec = 0;
+        if(!ptv){
+                                 ptv->tv_sec = 0;
+                                 ptv->tv_usec = 0;
+        }
                                return;
                }

Index: B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/mr.c
===================================================================
--- B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/mr.c   (revision 9352)
+++ B:/users/leonid/svn/winib/branches/MLNX_WinOF-3_0_0/hw/mlx4/kernel/bus/net/mr.c                (revision 9353)
@@ -774,10 +774,10 @@
                                mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
                }

                -static inline int mlx4_check_fmr(struct mlx4_fmr *fmr, u64 *page_list,
                +static inline int mlx4_check_fmr(struct mlx4_fmr *fmr,
                                int npages, u64 iova) {

                -              int i, page_mask;
                +             int page_mask;

                ASSERT(fmr != NULL);

                @@ -803,7 +803,7 @@
                u32 key;               int i, err;

                -              err = mlx4_check_fmr(fmr, page_list, npages, iova);
                +             err = mlx4_check_fmr(fmr, npages, iova);

                if (err)
                                return err;

                @@ -849,7 +849,7 @@
                u32 key;               int i, err;

                -              err = mlx4_check_fmr(fmr, page_list, npages, iova);
                +             err = mlx4_check_fmr(fmr, npages, iova);

                                if (err)
                                                return err;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20111213/376106c8/attachment.html>


More information about the ofw mailing list