From patchwork Tue Mar 7 00:34:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 9607895 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 7A01960414 for ; Tue, 7 Mar 2017 00:36:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FF222846A for ; Tue, 7 Mar 2017 00:36:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 521062848D; Tue, 7 Mar 2017 00:36:39 +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 3815C2846A for ; Tue, 7 Mar 2017 00:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753750AbdCGAgf (ORCPT ); Mon, 6 Mar 2017 19:36:35 -0500 Received: from smtprelay0054.hostedemail.com ([216.40.44.54]:38874 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753129AbdCGAgf (ORCPT ); Mon, 6 Mar 2017 19:36:35 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 4E2289EA14; Tue, 7 Mar 2017 00:34:11 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: pan95_7baff1cf3e91b X-Filterd-Recvd-Size: 5857 Received: from joe-laptop.perches.com (unknown [47.151.132.55]) (Authenticated sender: joe@perches.com) by omf09.hostedemail.com (Postfix) with ESMTPA; Tue, 7 Mar 2017 00:34:09 +0000 (UTC) From: Joe Perches To: SF Markus Elfring , Faisal Latif Cc: Doug Ledford , Sean Hefty , Hal Rosenstock , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] IB/nes: Neaten nes_alloc_mw Date: Mon, 6 Mar 2017 16:34:08 -0800 Message-Id: <72ea61362cbbd596fbf395ef32c63b64b62cddb8.1488845045.git.joe@perches.com> X-Mailer: git-send-email 2.10.0.rc2.1.g053435c In-Reply-To: <1488825451.2210.14.camel@perches.com> References: <1488825451.2210.14.camel@perches.com> 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 Convert the function to follow more typical kernel style. Use an error return block instead of individual returns. Reduces the object code size a trivial amount. $ size drivers/infiniband/hw/nes/nes_verbs.o* text data bss dec hex filename 26864 96 12 26972 695c drivers/infiniband/hw/nes/nes_verbs.o.new 26932 96 12 27040 69a0 drivers/infiniband/hw/nes/nes_verbs.o.old Signed-off-by: Joe Perches --- Markus, please try to improve the code for human readers instead of doing these mechanical conversions. Something like the below seems nicer to me. I hope one day it'll seem nicer to you too and you make the effort to understand and then fix the code style a little more than doing those apparently completely mindless conversions. drivers/infiniband/hw/nes/nes_verbs.c | 73 ++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c index ccf0a4cffe9c..5fe5af39f834 100644 --- a/drivers/infiniband/hw/nes/nes_verbs.c +++ b/drivers/infiniband/hw/nes/nes_verbs.c @@ -86,15 +86,15 @@ static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd, enum ib_mw_type type, next_stag_index %= nesadapter->max_mr; ret = nes_alloc_resource(nesadapter, nesadapter->allocated_mrs, - nesadapter->max_mr, &stag_index, &next_stag_index, NES_RESOURCE_MW); - if (ret) { + nesadapter->max_mr, &stag_index, + &next_stag_index, NES_RESOURCE_MW); + if (ret) return ERR_PTR(ret); - } nesmr = kzalloc(sizeof(*nesmr), GFP_KERNEL); if (!nesmr) { - nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index); - return ERR_PTR(-ENOMEM); + ret = -ENOMEM; + goto err_free_res; } stag = stag_index << 8; @@ -102,49 +102,55 @@ static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd, enum ib_mw_type type, stag += (u32)stag_key; nes_debug(NES_DBG_MR, "Registering STag 0x%08X, index = 0x%08X\n", - stag, stag_index); + stag, stag_index); /* Register the region with the adapter */ cqp_request = nes_get_cqp_request(nesdev); - if (cqp_request == NULL) { - kfree(nesmr); - nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index); - return ERR_PTR(-ENOMEM); + if (!cqp_request) { + ret = -ENOMEM; + goto err_kfree; } cqp_request->waiting = 1; cqp_wqe = &cqp_request->cqp_wqe; cqp_wqe->wqe_words[NES_CQP_WQE_OPCODE_IDX] = - cpu_to_le32( NES_CQP_ALLOCATE_STAG | NES_CQP_STAG_RIGHTS_REMOTE_READ | - NES_CQP_STAG_RIGHTS_REMOTE_WRITE | NES_CQP_STAG_VA_TO | - NES_CQP_STAG_REM_ACC_EN); + cpu_to_le32((NES_CQP_ALLOCATE_STAG | + NES_CQP_STAG_RIGHTS_REMOTE_READ | + NES_CQP_STAG_RIGHTS_REMOTE_WRITE | + NES_CQP_STAG_VA_TO | + NES_CQP_STAG_REM_ACC_EN)); nes_fill_init_cqp_wqe(cqp_wqe, nesdev); - set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX, (nespd->pd_id & 0x00007fff)); - set_wqe_32bit_value(cqp_wqe->wqe_words, NES_CQP_STAG_WQE_STAG_IDX, stag); + set_wqe_32bit_value(cqp_wqe->wqe_words, + NES_CQP_STAG_WQE_LEN_HIGH_PD_IDX, + nespd->pd_id & 0x00007fff); + set_wqe_32bit_value(cqp_wqe->wqe_words, + NES_CQP_STAG_WQE_STAG_IDX, + stag); atomic_set(&cqp_request->refcount, 2); nes_post_cqp_request(nesdev, cqp_request); /* Wait for CQP */ - ret = wait_event_timeout(cqp_request->waitq, (cqp_request->request_done != 0), - NES_EVENT_TIMEOUT); - nes_debug(NES_DBG_MR, "Register STag 0x%08X completed, wait_event_timeout ret = %u," - " CQP Major:Minor codes = 0x%04X:0x%04X.\n", - stag, ret, cqp_request->major_code, cqp_request->minor_code); - if ((!ret) || (cqp_request->major_code)) { - nes_put_cqp_request(nesdev, cqp_request); - kfree(nesmr); - nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index); - if (!ret) { - return ERR_PTR(-ETIME); - } else { - return ERR_PTR(-ENOMEM); - } - } + ret = wait_event_timeout(cqp_request->waitq, + cqp_request->request_done != 0, + NES_EVENT_TIMEOUT); + + nes_debug(NES_DBG_MR, "Register STag 0x%08X completed, wait_event_timeout ret = %u, CQP Major:Minor codes = 0x%04X:0x%04X\n", + stag, ret, cqp_request->major_code, cqp_request->minor_code); + nes_put_cqp_request(nesdev, cqp_request); + if (!ret) { + ret = -ETIME; + goto err_kfree; + } + if (cqp_request->major_code) { + ret = -ENOMEM; + goto err_kfree; + } + nesmr->ibmw.rkey = stag; nesmr->mode = IWNES_MEMREG_TYPE_MW; ibmw = &nesmr->ibmw; @@ -152,8 +158,13 @@ static struct ib_mw *nes_alloc_mw(struct ib_pd *ibpd, enum ib_mw_type type, nesmr->pbls_used = 0; return ibmw; -} +err_kfree: + kfree(nesmr); +err_free_res: + nes_free_resource(nesadapter, nesadapter->allocated_mrs, stag_index); + return ERR_PTR(ret); +} /** * nes_dealloc_mw