From patchwork Sat Nov 4 13:15:17 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: 10041567 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 BE4F860567 for ; Sat, 4 Nov 2017 13:15:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD642294FB for ; Sat, 4 Nov 2017 13:15:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2303295F4; Sat, 4 Nov 2017 13:15:36 +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=unavailable 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 43CD1294FB for ; Sat, 4 Nov 2017 13:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756710AbdKDNPW (ORCPT ); Sat, 4 Nov 2017 09:15:22 -0400 Received: from mout.web.de ([212.227.17.11]:59935 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751777AbdKDNPV (ORCPT ); Sat, 4 Nov 2017 09:15:21 -0400 Received: from [192.168.1.3] ([92.226.117.170]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0M7bQ3-1dErSq1KVD-00xM6r; Sat, 04 Nov 2017 14:15:19 +0100 Subject: [PATCH 1/4] target: Use common error handling code in three functions From: SF Markus Elfring To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Nicholas A. Bellinger" Cc: LKML , kernel-janitors@vger.kernel.org References: <27e27d42-473d-e8db-fe9e-803fed646881@users.sourceforge.net> Message-ID: <437fc193-6cf4-e9e3-3a0c-be34c9d1d58d@users.sourceforge.net> Date: Sat, 4 Nov 2017 14:15:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <27e27d42-473d-e8db-fe9e-803fed646881@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:U1TCtUWRNd9kugUNrW9uZRhjBc/+DGroH2oSI17bHKoeY51BgZv vfs0sUK1vtgiqUc2QlEK9HfPir7BZ8OCQHgYtT+YL7n82A5LCjnZCKARBNnIINwkr2QhtGb U8p0n6uNuRcxZdDp8DiHe4+Q/0MhKJyFTe5KUakWBGPB502EaljpdQEIUAjSJE0axBc5H9g a5aCOXF1pFiI87O6fgrHQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:bCWhD3o/kkk=:YfCTEV1l4YPJgOE/8j0d3v lug4AT/RiG67RHzBSLOXnGuV1VNO/gkmiuS40lmMu0I/OigUHAoR9aIM8KCpT+micKIR0xfkw OaWCdU9BVDCBnFgv/SfxSByy0PDy7Aj44R+/K/L+bE+4Fk46G0HWojoCOcViar3mRdPXZVi2f rE0OPVpBFoJAAH10evXXS9pJJAZlKE2w/vF71eTxskouHq88Y++IO3HkqpHxeHcGy1xlMhK63 mxk26jAL1G+roHGt229yYBDsltHaXYjdW2kSIf4KGjUb7K6m+9treuEad26vVU42thaKJnBzZ 0koJJJzLwShoy6Ijo47jo+aqyf6Waq6LKjE8Mlszou2+9TWNGkEWO2Q/WTXTmfY/Y8DwPkW3v 25sAk0jrgNQ0D1d2Nsn4eJp3amu9lBr8C4gYmZzC/CyTjzyKbkSoCANo2wwU9gzEd88f1dR4R v6On7i4ojtNjf0UqRkyfflissG0887lzwQGJhVMI10+N8tddhI40egCa/lMlGYIf3ZQ5smu7A OCpNcSUXj9ZG8Y0TgEaRopej+q0NZ5M6g8WtiObRCSj6wrt+N6/kcz6fefQD9rqCoK2xfFjLQ +9yKWE/gYf3mfw5i2u2F2P+r6mIKevj5yeSDUS1UTTxKUroVJy3oALcxUKXaPU/pExMaZE2vT kCY2UXbMaaac5bLvKTw8o8Rf0nEfQUDpA01zBi3B/gVSwxFrtkgiCjQdXRkHQm+AsAEsWjsXu 0oUP6bGjO2LnmWJPGSFTXEuuXwQD/lmjSeSA4OBFudut3+WSfJuomvvuGPG7dnknPfkME1Ero o+kwZzi7g0oDVuOvs9LEECBUw4LM5jkK7pnjxD7ydzB/su8Ny4= Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 4 Nov 2017 13:13:20 +0100 Adjust jump targets so that a bit of exception handling can be better reused at the end of these functions. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/target/target_core_xcopy.c | 49 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c index 9ee89e00cd77..b06877c57765 100644 --- a/drivers/target/target_core_xcopy.c +++ b/drivers/target/target_core_xcopy.c @@ -701,11 +701,8 @@ static int target_xcopy_read_source( rc = target_xcopy_setup_pt_cmd(xpt_cmd, xop, src_dev, &cdb[0], remote_port, true); - if (rc < 0) { - ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status; - transport_generic_free_cmd(se_cmd, 0); - return rc; - } + if (rc < 0) + goto set_status; xop->xop_data_sg = se_cmd->t_data_sg; xop->xop_data_nents = se_cmd->t_data_nents; @@ -713,11 +710,9 @@ static int target_xcopy_read_source( " memory\n", xop->xop_data_sg, xop->xop_data_nents); rc = target_xcopy_issue_pt_cmd(xpt_cmd); - if (rc < 0) { - ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status; - transport_generic_free_cmd(se_cmd, 0); - return rc; - } + if (rc < 0) + goto set_status; + /* * Clear off the allocated t_data_sg, that has been saved for * zero-copy WRITE submission reuse in struct xcopy_op.. @@ -726,6 +721,11 @@ static int target_xcopy_read_source( se_cmd->t_data_nents = 0; return 0; + +set_status: + ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status; + transport_generic_free_cmd(se_cmd, 0); + return rc; } static int target_xcopy_write_destination( @@ -775,19 +775,21 @@ static int target_xcopy_write_destination( src_cmd->t_data_sg = xop->xop_data_sg; src_cmd->t_data_nents = xop->xop_data_nents; - transport_generic_free_cmd(se_cmd, 0); - return rc; + goto err_free_cmd; } rc = target_xcopy_issue_pt_cmd(xpt_cmd); if (rc < 0) { ec_cmd->scsi_status = xpt_cmd->se_cmd.scsi_status; se_cmd->se_cmd_flags &= ~SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC; - transport_generic_free_cmd(se_cmd, 0); - return rc; + goto err_free_cmd; } return 0; + +err_free_cmd: + transport_generic_free_cmd(se_cmd, 0); + return rc; } static void target_xcopy_do_work(struct work_struct *work) @@ -801,10 +803,10 @@ static void target_xcopy_do_work(struct work_struct *work) unsigned short nolb, cur_nolb, max_nolb, copied_nolb = 0; if (target_parse_xcopy_cmd(xop) != TCM_NO_SENSE) - goto err_free; + goto err_free_xop; if (WARN_ON_ONCE(!xop->src_dev) || WARN_ON_ONCE(!xop->dst_dev)) - goto err_free; + goto err_free_xop; src_dev = xop->src_dev; dst_dev = xop->dst_dev; @@ -835,7 +837,7 @@ static void target_xcopy_do_work(struct work_struct *work) rc = target_xcopy_read_source(ec_cmd, xop, src_dev, src_lba, cur_nolb); if (rc < 0) - goto out; + goto err_undepend_device; src_lba += cur_nolb; pr_debug("target_xcopy_do_work: Incremented READ src_lba to %llu\n", @@ -846,10 +848,8 @@ static void target_xcopy_do_work(struct work_struct *work) rc = target_xcopy_write_destination(ec_cmd, xop, dst_dev, dst_lba, cur_nolb); - if (rc < 0) { - transport_generic_free_cmd(&xop->src_pt_cmd->se_cmd, 0); - goto out; - } + if (rc < 0) + goto err_free_cmd; dst_lba += cur_nolb; pr_debug("target_xcopy_do_work: Incremented WRITE dst_lba to %llu\n", @@ -876,10 +876,11 @@ static void target_xcopy_do_work(struct work_struct *work) target_complete_cmd(ec_cmd, SAM_STAT_GOOD); return; -out: +err_free_cmd: + transport_generic_free_cmd(&xop->src_pt_cmd->se_cmd, 0); +err_undepend_device: xcopy_pt_undepend_remotedev(xop); - -err_free: +err_free_xop: kfree(xop); /* * Don't override an error scsi status if it has already been set