]> git.openfabrics.org - ~shefty/libibverbs.git/commitdiff
Fix several valgrind false positives
authorDotan Barak <dotanb@dev.mellanox.co.il>
Wed, 10 Oct 2007 09:25:18 +0000 (11:25 +0200)
committerRoland Dreier <rolandd@cisco.com>
Fri, 15 Feb 2008 21:18:41 +0000 (13:18 -0800)
Fix several issues that were reported by valgrind:

* Initialize reserved attributes of command structures

* Fix the pointer and size when calling VALGRIND_MAKE_MEM_DEFINED in
  ibv_cmd_reg_mr() and ibv_cmd_create_cq_v2(): if we have struct
  xxx_resp *resp and resp_size, we need to do

VALGRIND_MAKE_MEM_DEFINED(resp, resp_size)

  rather than the getting the paramters wrong as in

VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp)
VALGRIND_MAKE_MEM_DEFINED(resp, sizeof resp_size);

* Call VALGRIND_MAKE_MEM_DEFINED for buffers that are filled by
  the kernel in ibv_cmd_query_srq(), ibv_cmd_destroy_srq() and
  ibv_cmd_query_qp().

Signed-off-by: Dotan Barak <dotanb@dev.mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
src/cmd.c

index 31b592e92101e0a8db4e964b1c5d67c57e300009..9db8aa615bf1f30394702c9f08ebb107309ff909 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -248,7 +248,7 @@ int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
        if (write(pd->context->cmd_fd, cmd, cmd_size) != cmd_size)
                return errno;
 
-       VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);
+       VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
        mr->handle  = resp->mr_handle;
        mr->lkey    = resp->lkey;
@@ -291,7 +291,7 @@ static int ibv_cmd_create_cq_v2(struct ibv_context *context, int cqe,
        if (write(context->cmd_fd, cmd, cmd_size) != cmd_size)
                return errno;
 
-       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof resp_size);
+       VALGRIND_MAKE_MEM_DEFINED(resp, resp_size);
 
        cq->handle  = resp->cq_handle;
        cq->cqe     = resp->cqe;
@@ -432,6 +432,7 @@ int ibv_cmd_destroy_cq(struct ibv_cq *cq)
 
        IBV_INIT_CMD_RESP(&cmd, sizeof cmd, DESTROY_CQ, &resp, sizeof resp);
        cmd.cq_handle = cq->handle;
+       cmd.reserved  = 0;
 
        if (write(cq->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd)
                return errno;
@@ -539,10 +540,13 @@ int ibv_cmd_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr,
 
        IBV_INIT_CMD_RESP(cmd, cmd_size, QUERY_SRQ, &resp, sizeof resp);
        cmd->srq_handle = srq->handle;
+       cmd->reserved   = 0;
 
        if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size)
                return errno;
 
+       VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);
+
        srq_attr->max_wr    = resp.max_wr;
        srq_attr->max_sge   = resp.max_sge;
        srq_attr->srq_limit = resp.srq_limit;
@@ -573,10 +577,13 @@ int ibv_cmd_destroy_srq(struct ibv_srq *srq)
 
        IBV_INIT_CMD_RESP(&cmd, sizeof cmd, DESTROY_SRQ, &resp, sizeof resp);
        cmd.srq_handle = srq->handle;
+       cmd.reserved   = 0;
 
        if (write(srq->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd)
                return errno;
 
+       VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);
+
        pthread_mutex_lock(&srq->mutex);
        while (srq->events_completed != resp.events_reported)
                pthread_cond_wait(&srq->cond, &srq->mutex);
@@ -657,6 +664,8 @@ int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
        if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size)
                return errno;
 
+       VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);
+
        attr->qkey                          = resp.qkey;
        attr->rq_psn                        = resp.rq_psn;
        attr->sq_psn                        = resp.sq_psn;
@@ -1067,6 +1076,7 @@ int ibv_cmd_destroy_qp(struct ibv_qp *qp)
 
        IBV_INIT_CMD_RESP(&cmd, sizeof cmd, DESTROY_QP, &resp, sizeof resp);
        cmd.qp_handle = qp->handle;
+       cmd.reserved  = 0;
 
        if (write(qp->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd)
                return errno;
@@ -1089,6 +1099,7 @@ int ibv_cmd_attach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid)
        memcpy(cmd.gid, gid->raw, sizeof cmd.gid);
        cmd.qp_handle = qp->handle;
        cmd.mlid      = lid;
+       cmd.reserved  = 0;
 
        if (write(qp->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd)
                return errno;
@@ -1104,6 +1115,7 @@ int ibv_cmd_detach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid)
        memcpy(cmd.gid, gid->raw, sizeof cmd.gid);
        cmd.qp_handle = qp->handle;
        cmd.mlid      = lid;
+       cmd.reserved  = 0;
 
        if (write(qp->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd)
                return errno;