From patchwork Thu Aug 18 17:32:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarod Wilson X-Patchwork-Id: 9289119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D7301607FF for ; Fri, 19 Aug 2016 01:54:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7A052915B for ; Fri, 19 Aug 2016 01:54:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC70E29161; Fri, 19 Aug 2016 01:54:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89E9F2915B for ; Fri, 19 Aug 2016 01:54:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754306AbcHSByJ (ORCPT ); Thu, 18 Aug 2016 21:54:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47740 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754301AbcHSBsg (ORCPT ); Thu, 18 Aug 2016 21:48:36 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A91A63F725; Thu, 18 Aug 2016 17:32:41 +0000 (UTC) Received: from hp-dl360pgen8-07.khw.lab.eng.bos.redhat.com (hp-dl360pgen8-07.khw.lab.eng.bos.redhat.com [10.16.184.47]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7IHWUAM018884; Thu, 18 Aug 2016 13:32:41 -0400 From: Jarod Wilson To: linux-rdma@vger.kernel.org Cc: Jarod Wilson , Gil Rockah Subject: [PATCH perftest 20/23] raw_ethernet_send_lat: prevent possible destroy on uninit val Date: Thu, 18 Aug 2016 13:32:15 -0400 Message-Id: <1471541538-20270-21-git-send-email-jarod@redhat.com> In-Reply-To: <1471541538-20270-1-git-send-email-jarod@redhat.com> References: <1471541538-20270-1-git-send-email-jarod@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 18 Aug 2016 17:32:41 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Because user_param gets twiddled so much, coverity/clang think it could be possible for the value of user_param.flows to change over time, which could result in trying to call ibv_destroy_flow() on an uninitialized flow_create_result[i]. Just save user_param.flows to a local variable and use it for loop iterations to ensure consistency. CC: Gil Rockah Signed-off-by: Jarod Wilson --- src/raw_ethernet_send_lat.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/raw_ethernet_send_lat.c b/src/raw_ethernet_send_lat.c index 6d0bbf9..b6bce26 100755 --- a/src/raw_ethernet_send_lat.c +++ b/src/raw_ethernet_send_lat.c @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) struct ibv_flow_attr **flow_rules; #endif struct report_options report; - int i; + int i, flows; /* allocate memory space for user parameters &*/ memset(&ctx, 0, sizeof(struct pingpong_context)); @@ -104,12 +104,13 @@ int main(int argc, char *argv[]) DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__); return FAILURE; } + flows = user_param.flows; #ifdef HAVE_RAW_ETH_EXP - ALLOCATE(flow_create_result, struct ibv_exp_flow*, user_param.flows); - ALLOCATE(flow_rules, struct ibv_exp_flow_attr*, user_param.flows); + ALLOCATE(flow_create_result, struct ibv_exp_flow*, flows); + ALLOCATE(flow_rules, struct ibv_exp_flow_attr*, flows); #else - ALLOCATE(flow_create_result, struct ibv_flow*, user_param.flows); - ALLOCATE(flow_rules, struct ibv_flow_attr*, user_param.flows); + ALLOCATE(flow_create_result, struct ibv_flow*, flows); + ALLOCATE(flow_rules, struct ibv_flow_attr*, flows); #endif @@ -160,7 +161,7 @@ int main(int argc, char *argv[]) /* Print basic test information. */ ctx_print_test_info(&user_param); - for (i = 0; i < user_param.flows; i++) + for (i = 0; i < flows; i++) print_spec(flow_rules[i], &user_param); /* Create (if necessary) the rdma_cm ids and channel. */ @@ -196,7 +197,7 @@ int main(int argc, char *argv[]) /* attaching the qp to the spec */ - for (i = 0; i < user_param.flows; i++) { + for (i = 0; i < flows; i++) { #ifdef HAVE_RAW_ETH_EXP flow_create_result[i] = ibv_exp_create_flow(ctx.qp[0], flow_rules[i]); #else @@ -274,7 +275,7 @@ int main(int argc, char *argv[]) #endif /* destroy flow */ - for (i = 0; i < user_param.flows; i++) { + for (i = 0; i < flows; i++) { #ifdef HAVE_RAW_ETH_EXP if (ibv_exp_destroy_flow(flow_create_result[i])) { #else @@ -292,14 +293,15 @@ int main(int argc, char *argv[]) if (destroy_ctx(&ctx, &user_param)) { fprintf(stderr,"Failed to destroy_ctx\n"); DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__); - return FAILURE; + goto free_flows; } if (user_param.output == FULL_VERBOSITY) printf(RESULT_LINE); DEBUG_LOG(TRACE,"<<<<<<%s",__FUNCTION__); - return 0; + ret_val = SUCCESS; + goto free_flows; eexists: ret_val = 17;