From patchwork Tue Oct 27 22:03:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 7504361 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 696209F327 for ; Tue, 27 Oct 2015 22:03:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F693209CB for ; Tue, 27 Oct 2015 22:03:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D4F6209C4 for ; Tue, 27 Oct 2015 22:03:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754001AbbJ0WDu (ORCPT ); Tue, 27 Oct 2015 18:03:50 -0400 Received: from mail-bn1on0077.outbound.protection.outlook.com ([157.56.110.77]:13184 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754642AbbJ0WDM (ORCPT ); Tue, 27 Oct 2015 18:03:12 -0400 Received: from BLUPR02CA037.namprd02.prod.outlook.com (10.160.23.155) by BY2PR0201MB0742.namprd02.prod.outlook.com (10.160.124.24) with Microsoft SMTP Server (TLS) id 15.1.306.13; Tue, 27 Oct 2015 22:03:10 +0000 Received: from BL2FFO11FD040.protection.gbl (2a01:111:f400:7c09::166) by BLUPR02CA037.outlook.office365.com (2a01:111:e400:8ad::27) with Microsoft SMTP Server (TLS) id 15.1.306.13 via Frontend Transport; Tue, 27 Oct 2015 22:03:10 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; dev.mellanox.co.il; dkim=none (message not signed) header.d=none;dev.mellanox.co.il; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BL2FFO11FD040.mail.protection.outlook.com (10.173.161.136) with Microsoft SMTP Server id 15.1.306.13 via Frontend Transport; Tue, 27 Oct 2015 22:03:09 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id C3.D7.32178.D94FF265; Tue, 27 Oct 2015 15:03:09 -0700 (PDT) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.248.2; Tue, 27 Oct 2015 15:03:08 -0700 X-AuditID: ac160a69-f79f76d000007db2-36-562ff49df8a1 Received: from [10.60.52.33] ( [10.177.8.100]) by milsmgip11.sandisk.com (Symantec Messaging Gateway) with SMTP id F4.8E.03643.C94FF265; Tue, 27 Oct 2015 15:03:08 -0700 (PDT) Subject: [PATCH 5/7] IB/srp: Fix srp_map_data() error paths To: Doug Ledford References: <562FF404.7000504@sandisk.com> CC: Sagi Grimberg , Sebastian Parschauer , "linux-rdma@vger.kernel.org" From: Bart Van Assche Message-ID: <562FF49C.2060009@sandisk.com> Date: Tue, 27 Oct 2015 15:03:08 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <562FF404.7000504@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRmVeSWpSXmKPExsWyRoxnke7cL/phBidWMFq8PP+B1eLZoV4W i9fHnzJZnLzN78DiMX3GJlaPP38+M3u833eVzePzJrkAligum5TUnMyy1CJ9uwSujOWN1xgL LgpUvJ+1nbGBcS1vFyMnh4SAiUTDokVsELaYxIV768F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ppMBcda6/kDvjpHrLxa+aDUIbrL38/mXtCVFy+95OL /F7GQ0uObT55bOrndFO+SU/6/+zSD32psurBwQiPo6HaXDGPAnT9tv+e6Ht/e/fyY9Fr7uYb PNTPu5Jk7pd//1N8h5TIqpPvr5uu4/Kdx+67iqdusxJLcUaioRZzUXEiAPAkULQDAgAA X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD040; 1:i+/yeOcge+EE7GYSbMg9L8reWqBmvcUlc7ZIYO51z6dW2bvlEwYB8+jOXz82pRyooVPQyXQob1bFvesx7l5SgwU5uxsdj9JP6kGLNajonH/ARIhDh2gp/eq7N2qewo2Rj9qqwZz3s3dmX+okkWyS30mj6/ZFZ7Y9aJ5rzUpzutjkFmXoAgsGvrq1lskzXaMqzBZwFsscaZGeyN7iAoYKGzm6YVDBJmL14MwfLGFsZXX3qkQgNgfB+lTf+JDG7tmBDjYAZdNHlZ4ExZuFgJDHe3d5wuLx8XKsMa6/kUcza/vW/Eeb3T/G1u2qTTv2FmPBPASnc4rZo1CEAfjJldmGm2pX1th3KpFJAu09n/Y6Jnv9gnz0cwJfyT6P5OZj9pc+66eNrD2H4pIwUtdxsNZZVA== X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(5008740100001)(80316001)(47776003)(19580395003)(50466002)(2950100001)(19580405001)(69596002)(11100500001)(77096005)(23676002)(5007970100001)(65956001)(92566002)(59896002)(106466001)(97736004)(81156007)(5001960100002)(65816999)(83506001)(50986999)(54356999)(87266999)(189998001)(110136002)(76176999)(87936001)(229853001)(33656002)(4001350100001)(36756003)(64126003)(86362001)(65806001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0201MB0742; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2PR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MADnmyNHkXpX8y5pyJCBz4xT0F6/6Dy13mmCxUqSM1lJsr2UhkrQ8eamj3MEnbel+DM7xbgBvCIwXdk7ag0M/JinDtJV8q3oRFveAAF+64dup+KL+UynqJqjbhVTUpeH8UEZsNktZGTrUwkQdrZpOmg5Cg5HU0+aize8bqNuVgZrYcWfHEb3eBd99CO4kK0XdxR8A2w75PDOGPEt1s49WgLHbuyCqIftK8UKb2AYyfILra44yjvuYc00cqmMqXjYFUjjwFJ2lFTeVlivy4SLt8V3stHTp5189q2lH; 4:A4SdMbQXWvX/OFkK697KC4P0bJDzj6VFeJSBqMz1yvUCOtVBF+BSXnXWV/qohgBc99TVaCNVdI17NwD8hqxUtLaPV8t/sE9j77A9TA0Knw6grfh/T/FluqpH421RKlQ6HrZfD2i6uqC+arjh6FwlRcCCPFv9vQPCjccfVReTNrGdHGjQ+Xvw04/uLYIpnj0oxuri/mY5/iswqObUlU0C+UpBjokdZFz55Kdvq4AcTCCCkh6rR9GjDVuyfGtaCy0Lv2ZhM9yXnvEQgK43/X6yEYspA3vBKI/KJ3vOP2Hui4KEk8KxMKUarM0EgLEL3+a8tklxLN8cCvSVngZE6MarBrfjp7i4CayXf0OeH5SGhIVONfFyEEywLcUp6fHDn3SP5vwpOgo1e4HNNNwUMmc0Tg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(34787635062028)(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(3002001)(10201501036)(102215026); SRVR:BY2PR0201MB0742; BCL:0; PCL:0; RULEID:; SRVR:BY2PR0201MB0742; X-Forefront-PRVS: 0742443479 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWTJQUjAyMDFNQjA3NDI7MjM6bmhmcDJMRXpnZGtqWitzWEIrZkV2WWZS?= =?utf-8?B?Q0locVNrYjViNklOdnBaeFU5SlE0UGNEVXEzekwveUFQVDJPcFhpSDBsSWRM?=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p79WFWZgQ23EN1lxYe7y0qFrZs/oGGOcZNK1jDlvJzhGfxDAL8OZ1xXDnGDpiUOnNuDRK4 SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2015 22:03:09.1197 (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.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0201MB0742 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Ensure that req->nmdesc is set correctly in srp_map_sg() if mapping fails. Avoid that mapping failure causes a memory descriptor leak. Report srp_map_sg() failure to the caller. Signed-off-by: Bart Van Assche Cc: Sagi Grimberg Cc: Sebastian Parschauer --- drivers/infiniband/ulp/srp/ib_srp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 6d17fe2..fb6b654 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -1473,7 +1473,6 @@ static int srp_map_sg(struct srp_map_state *state, struct srp_rdma_ch *ch, } } - req->nmdesc = state->nmdesc; ret = 0; out: @@ -1594,7 +1593,10 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch, target->indirect_size, DMA_TO_DEVICE); memset(&state, 0, sizeof(state)); - srp_map_sg(&state, ch, req, scat, count); + ret = srp_map_sg(&state, ch, req, scat, count); + req->nmdesc = state.nmdesc; + if (ret < 0) + goto unmap; /* We've mapped the request, now pull as much of the indirect * descriptor table as we can into the command buffer. If this @@ -1617,7 +1619,8 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch, !target->allow_ext_sg)) { shost_printk(KERN_ERR, target->scsi_host, "Could not fit S/G list into SRP_CMD\n"); - return -EIO; + ret = -EIO; + goto unmap; } count = min(state.ndesc, target->cmd_sg_cnt); @@ -1635,7 +1638,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch, ret = srp_map_idb(ch, req, state.gen.next, state.gen.end, idb_len, &idb_rkey); if (ret < 0) - return ret; + goto unmap; req->nmdesc++; } else { idb_rkey = target->global_mr->rkey; @@ -1661,6 +1664,10 @@ map_complete: cmd->buf_fmt = fmt; return len; + +unmap: + srp_unmap_data(scmnd, ch, req, true); + return ret; } /*