From patchwork Fri Feb 10 21:04:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9567515 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 1A495602B6 for ; Fri, 10 Feb 2017 21:05:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A6F3285D6 for ; Fri, 10 Feb 2017 21:05:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F37BB285D9; Fri, 10 Feb 2017 21:05:11 +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 AAB9F285D6 for ; Fri, 10 Feb 2017 21:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932151AbdBJVE5 (ORCPT ); Fri, 10 Feb 2017 16:04:57 -0500 Received: from mout.web.de ([212.227.17.11]:60811 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751460AbdBJVE4 (ORCPT ); Fri, 10 Feb 2017 16:04:56 -0500 Received: from [192.168.1.2] ([77.182.113.129]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MgOCo-1cnvsF42cw-00NgMr; Fri, 10 Feb 2017 22:04:42 +0100 Subject: [PATCH 4/5] IB/hfi1: Use memdup_user() rather than duplicating its implementation in hfi1_user_sdma_process_request() To: linux-rdma@vger.kernel.org, Dennis Dalessandro , Doug Ledford , Hal Rosenstock , Mike Marciniszyn , Sean Hefty References: <8a997282-09c7-0f9f-645e-d7c6e8c79e67@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: Date: Fri, 10 Feb 2017 22:04:38 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <8a997282-09c7-0f9f-645e-d7c6e8c79e67@users.sourceforge.net> X-Provags-ID: V03:K0:9kXhcqUQ3RvrSpQIqyj/GYWpRZfQwsaG6XhlapDyOaljgoPz6b1 xWVfCqHqEXpmDkA8uRCr7dyiBeBSrdp8GYHbiHOFxOeiDJVjDApvEQtJVoOyZzInVUKtxsS V0fMOQkmDHB/spif8bezPWNWDLXElDj4y4g/RMWZK1sSu3XYOuT8fcLW2Ke3bDdFF0i9XZn 6Bn2thM/+oPeQvi9tZ8FQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:43SkDYBrlV8=:LWgAkac/Ic9T5yFIeVr1yM fyML6eHr5gYOsumNahFlVSOHCw7TJTc15BMh5VxhzBEQ69m2QxPy+fj1+kyZT/yi2kTIL4wXE A5ApGNwg5ptS4tH2Z+HOlFvU5C90EyUHb2Coy4lgNhY1g3puywQuQR72yGAHvL6dF+iW4R1em A7iJaDy7wkRvqeiwgyY16yifWwPPyEs1yDETrVEJ7q+kDmnvq476WYSqyP4LHMGEtNLSS+0FM Yd3PBBWfDryWbyr0xf3l95WpS6KiG208H/tzifm3ogAXtBremUJKHhCIbneH5Q1nKti2UQL8U Y6+JWDwxeoFnBSoeHWiiSFE8e02ASPWTDM76xQs3V51/uxM9T/6Z2jrGtloMIydFbqaYAp8H5 ba/u9rUyPwyKHurYFIT9AM1VGRipahSW3TUZMmchKx2MI4TvMBQrhQDKoHdmT3jBRGekxsZsK kwFM1ST61oqPlFmfzl2iVEUSvwu7qg7GQvNQiPwBwhW3lAY2BDESGPEmvX3kcP0Js401ztcP7 thHyfJnsQ9UL7E+kWE9FMYB/ssvB9MVsh3K9F0EqljUiZMVrCZQ9sfHp6OCuRksEsqK19fvSK +2r/Nre7n2NcDOMPr3tDHX3QeAveaQp5QV1fJCnajX1YHlBpusmET4diYzPEgMx2z9DbOfTKA O2Yx3uJlZAm84LqdsZvDjmYFsB7YKenZpkn51Atwap8mYqkBo0ts37zZmXfLiLpIkFj3Ig133 XAwmlT/QkXZvhV3yr6r8lvwH2gGij629RKTQ50ncT1vFYegkSmc7DKQPkVoVOB3tktjIijloT eW5KcL1 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 From: Markus Elfring Date: Fri, 10 Feb 2017 21:01:55 +0100 Reuse existing functionality from memdup_user() instead of keeping duplicate source code. Signed-off-by: Markus Elfring --- drivers/infiniband/hw/hfi1/user_sdma.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/user_sdma.c b/drivers/infiniband/hw/hfi1/user_sdma.c index 991e7f3d8e18..5a73d738f2ba 100644 --- a/drivers/infiniband/hw/hfi1/user_sdma.c +++ b/drivers/infiniband/hw/hfi1/user_sdma.c @@ -731,23 +731,18 @@ int hfi1_user_sdma_process_request(struct file *fp, struct iovec *iovec, ret = -EINVAL; goto free_req; } - req->tids = kcalloc(ntids, sizeof(*req->tids), GFP_KERNEL); - if (!req->tids) { - ret = -ENOMEM; - goto free_req; - } /* * We have to copy all of the tids because they may vary * in size and, therefore, the TID count might not be * equal to the pkt count. However, there is no way to * tell at this point. */ - ret = copy_from_user(req->tids, iovec[idx].iov_base, - ntids * sizeof(*req->tids)); - if (ret) { + req->tids = memdup_user(iovec[idx].iov_base, + sizeof(*req->tids) * ntids); + if (IS_ERR(req->tids)) { + ret = PTR_ERR(req->tids); SDMA_DBG(req, "Failed to copy %d TIDs (%d)", ntids, ret); - ret = -EFAULT; goto free_req; } req->n_tids = ntids; @@ -1606,7 +1601,8 @@ static void user_sdma_free_request(struct user_sdma_request *req, bool unpin) atomic_dec(&node->refcount); } } - kfree(req->tids); + if (!IS_ERR(req->tids)) + kfree(req->tids); clear_bit(req->info.comp_idx, req->pq->req_in_use); }