From patchwork Wed Apr 6 18:57:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 8764521 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E460C0553 for ; Wed, 6 Apr 2016 18:57:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E50C2011D for ; Wed, 6 Apr 2016 18:57:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6301A2010B for ; Wed, 6 Apr 2016 18:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753135AbcDFS5a (ORCPT ); Wed, 6 Apr 2016 14:57:30 -0400 Received: from mail-bl2on0100.outbound.protection.outlook.com ([65.55.169.100]:1920 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752447AbcDFS52 (ORCPT ); Wed, 6 Apr 2016 14:57:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sandiskcorp.onmicrosoft.com; s=selector1-sandisk-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=e7nR2/fvjqf9X4/Cm9Uqce1Ox/U1a/Xk3z9WMGBJjvg=; b=led6UYjIuUgZYTC34nIkA+tqn6bB7Ta6TZNajAzxqZGIbBWXpDvCCOvk8Ya4nRcDQjzAUIcdfNysYqFdGh5zihgvuHq3yGW0PjP3vRhGJf9Ll4cHkue0Rla1W1l+VEZZPl7jp3XX+FNj7Xuk7BRZ2T25W2qckoGJBISnFoPxYdc= Received: from BY2PR02CA0087.namprd02.prod.outlook.com (10.242.32.45) by CY1PR0201MB1932.namprd02.prod.outlook.com (10.163.56.30) with Microsoft SMTP Server (TLS) id 15.1.447.15; Wed, 6 Apr 2016 18:57:24 +0000 Received: from BN1BFFO11FD007.protection.gbl (2a01:111:f400:7c10::1:141) by BY2PR02CA0087.outlook.office365.com (2a01:111:e400:2c2a::45) with Microsoft SMTP Server (TLS) id 15.1.447.15 via Frontend Transport; Wed, 6 Apr 2016 18:57:24 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.225) smtp.mailfrom=sandisk.com; lst.de; dkim=none (message not signed) header.d=none;lst.de; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.225 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.225; helo=milsmgep14.sandisk.com; Received: from milsmgep14.sandisk.com (63.163.107.225) by BN1BFFO11FD007.mail.protection.outlook.com (10.58.144.70) with Microsoft SMTP Server (TLS) id 15.1.453.6 via Frontend Transport; Wed, 6 Apr 2016 18:57:22 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com (Unknown_Domain [172.22.12.162]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id 96.D1.04010.8DB55075; Wed, 6 Apr 2016 11:56:24 -0700 (PDT) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.248.2; Wed, 6 Apr 2016 11:57:21 -0700 X-AuditID: ac160c71-33bff70000000faa-4e-57055bd843ea Received: from exp-402881.sandisk.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id 6F.E0.02566.01C55075; Wed, 6 Apr 2016 11:57:20 -0700 (PDT) Subject: [PATCH 3/4] IB/srpt: Introduce two helper functions To: Doug Ledford References: <57055BC6.7070402@sandisk.com> CC: "Nicholas A. Bellinger" , Christoph Hellwig , Sagi Grimberg , "linux-rdma@vger.kernel.org" , target-devel From: Bart Van Assche Message-ID: <57055C10.3060108@sandisk.com> Date: Wed, 6 Apr 2016 11:57:20 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <57055BC6.7070402@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRmVeSWpSXmKPExsWyRoxnke6NaNZwg++7NCxenv/AarFy9VEm i2eHelks2lafYbRY9/o9i0Xr0rdMDmwe5+9tZPG4v/0Ik8fumw1sHu/3XWXz+LxJLoA1issm JTUnsyy1SN8ugStj7YU1bAXPRCtO3nzJ3sB4WbCLkZNDQsBE4v7r5YxdjFwcQgJzmSRuPfvL AuFsZ5RYumc1E0zVlqkvWSESSxklDrxYwwiSEBawkbj+eiZYkYiAmsSmV4vYQWwhAS2Jyev6 wSYxC9xnlHizfAIzSIJNwEji2/uZLCA2L1DRwgd3wAaxCKhIHLo1jxXEFhWIkGh98JQdokZQ 4uTMJ2D1nALaEr+73gIt4wAaqimxfpc+SJhZQF5i+9s5zBCHHmWVOH2uGuIGdYmTS+YzTWAU noVk0iyE7llIuhcwMq9iFMvNzCnOTU8tMDTRK07MS8ksztZLzs/dxAiJk8IdjK9vex9iFOBg VOLhFbBiCRdiTSwrrsw9xCjBwawkwtsQwRouxJuSWFmVWpQfX1Sak1p8iFGag0VJnPdi9Mcw IYH0xJLU7NTUgtQimCwTB6dUA6NTzpvVM94Enc+ctIljl174SZHzaqtOTXG4/nHCw2XSUgz5 /XWP1pxLnfN85q8pIQGcbzVOCq/76mvM8ZjJaN7pOV1ZuTVL1T1aPq/Z0dPh+XXT+UtCZRdW OfjES9pvqdCrDUz5rnx1DqeRgW7GqUnvTk1d1P48PjRtUsz3O63q3JKnmPy3C75UYinOSDTU Yi4qTgQAW3qmF48CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCJMWRmVeSWpSXmKPExsXCtZEjRVcghjXcYPpCU4uX5z+wWqxcfZTJ 4tmhXhaLttVnGC3WvX7PYtG69C2TA5vH+XsbWTzubz/C5LH7ZgObx/t9V9k8Pm+SC2CN4rJJ Sc3JLEst0rdL4MpYe2ENW8Ez0YqTN1+yNzBeFuxi5OSQEDCR2DL1JWsXIxeHkMBiRonpH6Yz gSSEBWwkrr+eCWaLCKhJbHq1iB3EFhLQkpi8rp8FpIFZ4CGjxOeuOWBFbAJGEt/ez2QBsXmB ihY+uMMIYrMIqEgcujWPFcQWFYiQaH3wlB2iRlDi5MwnYPWcAtoSv7vegs1hFlCX+DPvEjOE LS+x/e0c5gmMfLOQtMxCUjYLSdkCRuZVjGK5mTnFuemZBYaGesWJeSmZxdl6yfm5mxjB4coZ uYPx6UTzQ4xMHJxSDYx7HtqdWeHeIuug8307b5KEclCb+jHLiReeB+Y5SK49bq0heKJAVNT7 mGvdCzHT+g/LDz7+5jbxHWcRt9+XR9EMsx9WvCnXO2Z80u2wAqPDsr5HG9avZj/7cMHOmc/k 72w7cuzvx2gbW/YrZ9Ye3ef9S1Jv7+ZZbOpy08TXmIRfPj9JZ11OpGuPEktxRqKhFnNRcSIA dmtaMAcCAAA= X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:63.163.107.225; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(189002)(199003)(80316001)(64126003)(83506001)(1220700001)(33656002)(4001350100001)(2906002)(23676002)(586003)(99136001)(86362001)(2270400002)(1096002)(19580405001)(50986999)(19580395003)(230700001)(77096005)(5008740100001)(87936001)(50466002)(53416004)(229853001)(81166005)(106466001)(59896002)(2950100001)(5003600100002)(36756003)(110136002)(4326007)(65816999)(76176999)(87266999)(11100500001)(6806005)(92566002)(189998001)(54356999); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0201MB1932; H:milsmgep14.sandisk.com; FPR:; SPF:Pass; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagn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QM0mn1gbS9wQpy4USu3/OUqojV1jeiEE0Aak9si5Oqatn23MaBEJ8Bx1kFUO8zaUOySXWNYwX9QvhAmExevfkEIf+S0qVflpKJxHYKMakHNKkTK/2ZmP2sHnNmvXcM6NeFErwaBLu/RTZ6KlQCxTq5bP7/B8sAG+2rSZ5ZwTPkRinN5ttyW6/mC4iS6E75AI306tMOFJInG/8kbkKFXEee8F/PuTo0S1vReWwwF6Ekl1zIQeJV6bYwRjwxDcRI2bEJLTi9ID+EV0RG3N7Ww91b8As9bJY55JNdSFPYn55YfOC9pYnGDm2HSjalLiEfEB/ewmakjPjl8ec 878YAhI= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13018025)(5005006)(8121501046)(13016025)(10201501046)(3002001); SRVR:CY1PR0201MB1932; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0201MB1932; X-Forefront-PRVS: 0904004ECB X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjAyMDFNQjE5MzI7MjM6YXJVTHFpWVBuaHYzVTNzeHVidGk1Uk1F?= =?utf-8?B?blVHWExnVXJnaG9hWXF3NHZVMDZvdlhTUkU5aE00VXVtR09RbnZvY2FiMytS?= =?utf-8?B?T09PWjZOelhyRVpKQzFwVHdXZVVsZE5LbCsxeWI3Ryt1Y0duREFuNVlPeXZL?= =?utf-8?B?aWQ5SVNsS3ZwL2gxcHhPMitSR2oxdHVta1k0WGZPTzA2L0xJdk8yaFdzR2Nj?= =?utf-8?B?TStBT0htbHgzV2syM1hoTk1QdW9JMFZBcVNHdmx2cFF4aEh6THNoTmx5cHhn?= =?utf-8?B?V3EzYkdVSEI1Rmo4VFI3d3RIVTlJWHhYWW9INWtCOXFDZmRrM0hxaTZjcGNx?= =?utf-8?B?TStsMllXWm9MSTFLMlhMZVpKVko3VlNFWExhazZONlE5RWtlUXdPZ0Y5elcy?= =?utf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QaHRYRlVGeWhQ?= =?utf-8?B?cHRHQVIrbVdNRU4xdUNveGxYei82bWtURENMMlFzK3pmQTFpclc5VlRZbkpV?= =?utf-8?B?ZXRJTnExcC8rQjZQOFVVTk1udDlVM25CZndCNmtLME5FSk41aVA0eTVXdThv?= =?utf-8?B?NkZTalhza1c0cld6TDNjVjhSc0hSdEZDVXJmSEZPeDlIZTBJM0VueVlRZHdI?= =?utf-8?B?MkZIWFJEdkNWKzFhZGltMFF5Ny80NGY2aFZRVHVsREI1Q2txZ2RpWTZGdnFM?= =?utf-8?Q?Mgb?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0201MB1932; 5:0Hi247GL9yXjkG4sC0Cr/eX+izYzgj5u3Cl56hQ6BqrfqTj84H1XsMELlZXItGIQLEvquh35EG0dcZig/gD240v2/OoMh7DE2xl11ElhOB+s4keMs2RTSbfaLLAL1IYkD4C/CD6rVkj+NuwsHMWp8w==; 24:qC7MyK/oJn2mX/jdpcDYFgTtumrYqIlouFFumwTQVIfzqT71q8cYSIm48DIJbZ75eTZetSglLxg1JF6/YG4uNbt5Xt5g+F59TYv+/UOwjkU=; 20:0Nrk/1NvdU9GOMXOCKjApBAiBL+PVtGWNkrVxETvTlrKTtSqC7JENSq/p8Bb8/xcZpP/sWC2iyJ339NrtyNHj+wQhybwVs2kM+JCm6/EqRSDiLUlnjpUXsd+HdQb/yaK06sA3fkIjlaXc5dQ39McaxsCc+q2ylH05+wABxhXsHFKTRyaK+8b7MvpxyLoBCkWBJi30iQwNOF+yDfdCzNpiQ3AEILQjRD0V11JkFX+2i44IiFUh/Zz4C2PL33cSYW2 SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2016 18:57:22.9696 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.225]; Helo=[milsmgep14.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0201MB1932 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the functionality for initializing and cleaning up I/O contexts into two new functions. This patch does not change any functionality. Signed-off-by: Bart Van Assche Cc: Nicholas Bellinger Cc: Christoph Hellwig Cc: Sagi Grimberg Reviewed-by: Christoph Hellwig --- drivers/infiniband/ulp/srpt/ib_srpt.c | 64 +++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 07dfc50..cce6c46 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -581,6 +581,31 @@ static void srpt_unregister_mad_agent(struct srpt_device *sdev) } } +static int srpt_init_ioctx(struct srpt_device *sdev, + struct srpt_ioctx *ioctx, + int dma_size, + enum dma_data_direction dir) +{ + int ret = -ENOMEM; + + ioctx->buf = kmalloc(dma_size, GFP_KERNEL); + if (!ioctx->buf) + goto out; + + ioctx->dma = ib_dma_map_single(sdev->device, ioctx->buf, dma_size, dir); + if (ib_dma_mapping_error(sdev->device, ioctx->dma)) + goto free_buf; + + ret = 0; + +out: + return ret; + +free_buf: + kfree(ioctx->buf); + goto out; +} + /** * srpt_alloc_ioctx() - Allocate an SRPT I/O context structure. */ @@ -592,24 +617,34 @@ static struct srpt_ioctx *srpt_alloc_ioctx(struct srpt_device *sdev, ioctx = kmalloc(ioctx_size, GFP_KERNEL); if (!ioctx) - goto err; - - ioctx->buf = kmalloc(dma_size, GFP_KERNEL); - if (!ioctx->buf) - goto err_free_ioctx; + goto out; - ioctx->dma = ib_dma_map_single(sdev->device, ioctx->buf, dma_size, dir); - if (ib_dma_mapping_error(sdev->device, ioctx->dma)) - goto err_free_buf; + if (srpt_init_ioctx(sdev, ioctx, dma_size, dir) < 0) + goto free; +out: return ioctx; -err_free_buf: - kfree(ioctx->buf); -err_free_ioctx: +free: kfree(ioctx); -err: - return NULL; + ioctx = NULL; + goto out; +} + +/* + * Note: it is safe to call this function for a zero-initialized buffer + * even if srpt_init_ioctx() has not been called. + */ +static void srpt_cleanup_ioctx(struct srpt_device *sdev, + struct srpt_ioctx *ioctx, + int dma_size, + enum dma_data_direction dir) +{ + if (!ioctx->buf) + return; + + ib_dma_unmap_single(sdev->device, ioctx->dma, dma_size, dir); + kfree(ioctx->buf); } /** @@ -621,8 +656,7 @@ static void srpt_free_ioctx(struct srpt_device *sdev, struct srpt_ioctx *ioctx, if (!ioctx) return; - ib_dma_unmap_single(sdev->device, ioctx->dma, dma_size, dir); - kfree(ioctx->buf); + srpt_cleanup_ioctx(sdev, ioctx, dma_size, dir); kfree(ioctx); }