From patchwork Sun Jan 1 14:17:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Gurtovoy X-Patchwork-Id: 9492893 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 49F3960416 for ; Sun, 1 Jan 2017 14:17:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F6071FF35 for ; Sun, 1 Jan 2017 14:17:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EF8D24603; Sun, 1 Jan 2017 14:17:24 +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, UNPARSEABLE_RELAY 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 6CAAD205AD for ; Sun, 1 Jan 2017 14:17:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755057AbdAAORU (ORCPT ); Sun, 1 Jan 2017 09:17:20 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:54198 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755109AbdAAORU (ORCPT ); Sun, 1 Jan 2017 09:17:20 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from maxg@mellanox.com) with ESMTPS (AES256-SHA encrypted); 1 Jan 2017 16:17:13 +0200 Received: from r-vnc08.mtr.labs.mlnx (r-vnc08.mtr.labs.mlnx [10.208.0.121]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v01EHCew004491; Sun, 1 Jan 2017 16:17:13 +0200 From: Max Gurtovoy To: bvanassche@acm.org, dledford@redhat.com, linux-rdma@vger.kernel.org Cc: israelr@mellanox.com, Max Gurtovoy Subject: [PATCH 1/2 v2] IB/srp: allocate ib_qp_attr on the stack Date: Sun, 1 Jan 2017 16:17:11 +0200 Message-Id: <1483280232-13826-2-git-send-email-maxg@mellanox.com> X-Mailer: git-send-email 1.7.8.2 In-Reply-To: <1483280232-13826-1-git-send-email-maxg@mellanox.com> References: <1483280232-13826-1-git-send-email-maxg@mellanox.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 No reason to use kmalloc that may increase memory fragmentation. This also simplifies the code in means of memory alloc/free in initialization flow. Tested-by: Israel Rukshin Signed-off-by: Max Gurtovoy --- drivers/infiniband/ulp/srp/ib_srp.c | 51 +++++++++++++---------------------- 1 files changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 8ddc071..c7f3e1e 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -268,33 +268,28 @@ static void srp_qp_event(struct ib_event *event, void *context) static int srp_init_qp(struct srp_target_port *target, struct ib_qp *qp) { - struct ib_qp_attr *attr; + struct ib_qp_attr attr = { 0 }; int ret; - attr = kmalloc(sizeof *attr, GFP_KERNEL); - if (!attr) - return -ENOMEM; - ret = ib_find_cached_pkey(target->srp_host->srp_dev->dev, target->srp_host->port, be16_to_cpu(target->pkey), - &attr->pkey_index); + &attr.pkey_index); if (ret) goto out; - attr->qp_state = IB_QPS_INIT; - attr->qp_access_flags = (IB_ACCESS_REMOTE_READ | + attr.qp_state = IB_QPS_INIT; + attr.qp_access_flags = (IB_ACCESS_REMOTE_READ | IB_ACCESS_REMOTE_WRITE); - attr->port_num = target->srp_host->port; + attr.port_num = target->srp_host->port; - ret = ib_modify_qp(qp, attr, + ret = ib_modify_qp(qp, &attr, IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_ACCESS_FLAGS | IB_QP_PORT); out: - kfree(attr); return ret; } @@ -2292,7 +2287,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id, struct srp_rdma_ch *ch) { struct srp_target_port *target = ch->target; - struct ib_qp_attr *qp_attr = NULL; + struct ib_qp_attr qp_attr = { 0 }; int attr_mask = 0; int ret; int i; @@ -2324,44 +2319,36 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id, goto error; } - ret = -ENOMEM; - qp_attr = kmalloc(sizeof *qp_attr, GFP_KERNEL); - if (!qp_attr) - goto error; - - qp_attr->qp_state = IB_QPS_RTR; - ret = ib_cm_init_qp_attr(cm_id, qp_attr, &attr_mask); + qp_attr.qp_state = IB_QPS_RTR; + ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &attr_mask); if (ret) - goto error_free; + goto error; - ret = ib_modify_qp(ch->qp, qp_attr, attr_mask); + ret = ib_modify_qp(ch->qp, &qp_attr, attr_mask); if (ret) - goto error_free; + goto error; for (i = 0; i < target->queue_size; i++) { struct srp_iu *iu = ch->rx_ring[i]; ret = srp_post_recv(ch, iu); if (ret) - goto error_free; + goto error; } - qp_attr->qp_state = IB_QPS_RTS; - ret = ib_cm_init_qp_attr(cm_id, qp_attr, &attr_mask); + qp_attr.qp_state = IB_QPS_RTS; + ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &attr_mask); if (ret) - goto error_free; + goto error; - target->rq_tmo_jiffies = srp_compute_rq_tmo(qp_attr, attr_mask); + target->rq_tmo_jiffies = srp_compute_rq_tmo(&qp_attr, attr_mask); - ret = ib_modify_qp(ch->qp, qp_attr, attr_mask); + ret = ib_modify_qp(ch->qp, &qp_attr, attr_mask); if (ret) - goto error_free; + goto error; ret = ib_send_cm_rtu(cm_id, NULL, 0); -error_free: - kfree(qp_attr); - error: ch->status = ret; }