From patchwork Fri Nov 3 21:33:08 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: 10041215 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 B4B73600C5 for ; Fri, 3 Nov 2017 21:33:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A61EF29960 for ; Fri, 3 Nov 2017 21:33:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B01729963; Fri, 3 Nov 2017 21:33:53 +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 55D0429960 for ; Fri, 3 Nov 2017 21:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754624AbdKCVdV (ORCPT ); Fri, 3 Nov 2017 17:33:21 -0400 Received: from mout.web.de ([212.227.15.3]:50404 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752284AbdKCVdT (ORCPT ); Fri, 3 Nov 2017 17:33:19 -0400 Received: from [192.168.1.3] ([78.49.7.122]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M8oFY-1dyc7032Pk-00C8Xp; Fri, 03 Nov 2017 22:33:11 +0100 To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Arun Easi , Bart Van Assche , "Nicholas A. Bellinger" Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] iSCSI-target: Use common error handling code in iscsi_decode_text_input() Message-ID: Date: Fri, 3 Nov 2017 22:33:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:epduhAPcS5QsaSUTM2U4hFCjHJUb5vPP6bLe1PFhgg+R0wVlXS/ hbDXoMYOZZFRoAj/eTn2kAzCs6dDa1OBaHksJi5yVUm93pjU/k/U6O2ibtiMH3a1WWxWMJ1 Pgfw3raTEiG1OAFbX2tP+URY0cp6tyz99pbudRr0zbSEABG/f8l7MV00eRyJqzAGogyWd25 MWSWzFKuwS9xxgCfrqkWQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:o1KwyL6qgIE=:WqXRZrp6s2A9chl4bhnPIw qHDMNU0MxOvc34ApvQUfGio7jieTes6EL0BY8nAZdy60l63Q2+w5Zu670hRTg5UlW8M5Ahs1g tSmgwHZT4xlmOYIGdrWMe+6cAcf7ZLEQL5JYunbzwJr/LuTBc3xJcOZxlcI5f3h4zLtUJLKwA aOdU+hnCXxYI4qtorIceJtQvw0/Ho+Dr3BG0MO3GmPBL2wk9ZYjf5wHcdHXK/nLh3Uxvr3IfC 5hNAyBF8RTyOLENSw9J6gd0mWTcjTIclDDJVShIjbz2gv9PJzDy9woP8hbqLLL5V+UtkXHlP6 SMM6Vx/x02COsozkn4PbQROjucoJSFZ6v2NC5YtFT857KNkXHKlA/lfM1ZU/cJbNw9QUt7Qnn NvSO7A26zKFLuHs/F5a5PEZ5qRNunBQnWWUyXxpBIfe+CAxrROI3hGl+tu0qRERp7tSc8AV5T 6yjZuSalFQtwbULcoiOg3wURhlAlgHGbBDyBU9lmG18v2xnsh10J1PHGFRRt2kW2gLHIr6hBI 1mkuFU00U2wSM9dDxsSGe62zubMfho2Xoz48bikzEYhFMzOyQCcHcc22IO0ZGOUMKYRwWpZ+E B+tPHvORitwTgWc6rAAhRuHyNmXs/msSa/26Wx1uqZVOJ7PGX4Pa2okfSTiQqaBeufl7OQLAz gEl7NfxbJ8QEkpR1sVpzDOXt04G8lZAxBll09LkOK7HsIweH0ZLyHTp0f2J2G1axa+EaaT42C Ts+ULPjN42D1JMwoEl3o25h7Evhw/F3iLvw2uiCYwXG/DW3oQvVmhwMCHSmzvJ0JT6VP1HrYv VO7t/MyWYNLUCgMnUp0AswNqBTGoJ+vq8Y+PGTypeZmW0XlTFY= 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: Fri, 3 Nov 2017 22:20:38 +0100 Add a jump target so that a bit of exception handling can be better reused at the end of this function. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/target/iscsi/iscsi_target_parameters.c | 39 ++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c index caab1045742d..29a37b242d30 100644 --- a/drivers/target/iscsi/iscsi_target_parameters.c +++ b/drivers/target/iscsi/iscsi_target_parameters.c @@ -1380,10 +1380,8 @@ int iscsi_decode_text_input( char *key, *value; struct iscsi_param *param; - if (iscsi_extract_key_value(start, &key, &value) < 0) { - kfree(tmpbuf); - return -1; - } + if (iscsi_extract_key_value(start, &key, &value) < 0) + goto free_buffer; pr_debug("Got key: %s=%s\n", key, value); @@ -1396,38 +1394,37 @@ int iscsi_decode_text_input( param = iscsi_check_key(key, phase, sender, param_list); if (!param) { - if (iscsi_add_notunderstood_response(key, - value, param_list) < 0) { - kfree(tmpbuf); - return -1; - } + if (iscsi_add_notunderstood_response(key, value, + param_list) < 0) + goto free_buffer; + start += strlen(key) + strlen(value) + 2; continue; } - if (iscsi_check_value(param, value) < 0) { - kfree(tmpbuf); - return -1; - } + if (iscsi_check_value(param, value) < 0) + goto free_buffer; start += strlen(key) + strlen(value) + 2; if (IS_PSTATE_PROPOSER(param)) { - if (iscsi_check_proposer_state(param, value) < 0) { - kfree(tmpbuf); - return -1; - } + if (iscsi_check_proposer_state(param, value) < 0) + goto free_buffer; + SET_PSTATE_RESPONSE_GOT(param); } else { - if (iscsi_check_acceptor_state(param, value, conn) < 0) { - kfree(tmpbuf); - return -1; - } + if (iscsi_check_acceptor_state(param, value, conn) < 0) + goto free_buffer; + SET_PSTATE_ACCEPTOR(param); } } kfree(tmpbuf); return 0; + +free_buffer: + kfree(tmpbuf); + return -1; } int iscsi_encode_text_output(