From patchwork Sat Dec 12 14:37:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 7834971 Return-Path: X-Original-To: patchwork-linux-scsi@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 124C89F387 for ; Sat, 12 Dec 2015 14:37:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B3B3203AE for ; Sat, 12 Dec 2015 14:37:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5EAA6203AD for ; Sat, 12 Dec 2015 14:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752272AbbLLOhP (ORCPT ); Sat, 12 Dec 2015 09:37:15 -0500 Received: from mout.web.de ([212.227.17.12]:51664 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751330AbbLLOhN (ORCPT ); Sat, 12 Dec 2015 09:37:13 -0500 Received: from [192.168.1.2] ([78.49.180.156]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0MIvbh-1a5qQB3CWn-002Vju; Sat, 12 Dec 2015 15:37:10 +0100 Subject: [PATCH 2/7] iscsi-target: Less checks in iscsi_set_default_param() after error detection To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Nicholas A. Bellinger" References: <566ABCD9.1060404@users.sourceforge.net> <566C2F7B.6030704@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <566C310F.6040604@users.sourceforge.net> Date: Sat, 12 Dec 2015 15:37:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <566C2F7B.6030704@users.sourceforge.net> X-Provags-ID: V03:K0:gNBaqES0wViyyfq2+TwBeDPXKMwqgWMxibDLzdCA1gjT6C8Xa06 PFtb877pWfV/dcWy8sLCDtW61kseWeWGBnIKaYFsrrLZBqWXPdgnEokcBz/3BOGPqbEyF4J 94HzGyYzscis0jGn95JqDlSI8txwQ0qoHsgAyEUizaF6KsBqMdwTACWKbQplL+/oTIO6x0U YSDYgUDIH8KLlFBakoECA== X-UI-Out-Filterresults: notjunk:1; V01:K0:gnPiWLlkei4=:nPE2E6wO8kK/obJd0m5Ptb ++KC45RMjRqSzylU2KWJ8U8to0MgmJ0NwMHhFC+viveOG2ULd2F3N0ehKVDwhcA56RZt8suAL dJ2Y8KJeP67tEgkt/0GRkiwzJZFVQyyuA9OG4n/jiDmejtA8FPo4r/HCrEqcM29Y2MHdycB0A In+LmJBfYX0TvAHsthfBg/vDfVo7fp8ahu2xpSETaZlTEjG/BVkFlUhfRLoZVWoINlVjcCFyq yw4XBcHxIXnpFhBQqpA22Lkdj9iHBbKwNTWI8QAXA8TvRT6fIjvmlWb9IAAQqnuNhJGvP/9EG us3OIGZk2j9O0yjDeJhNPr3obth0Xc7hCw2N+MleUAyOvrpuqsPQc+NtFbko4DQMNCz/I+wh0 uu+tvKwQ+HABEzP8IGvWXsJkmX7mncst5b0OTsdZTnD9IFXSzxEpjh8jmQmVSRb+TjGqVWByi +KLsMuQKpqEwl+D6ri+ps+jMaqFi48qUHyJ0klBtlKOXP55vYydumWsFTzTGj53BE8vKpewKW xuxeZjnM784qWVnGhnQmndK91RMiondHHso1eY+seJc8Qt4WAeu9Mwn8TH58JECc4vJ89O+CI c20ghczNJkZv2/89SxdUDYP+4qIIH8KgENeo8rr/KvqVRX3l3fVQP30eGXpVThoeKQ0BkRIOv Y15fxq2ZQHKQrOvDe+sD7MzzIOyrrZigmnFECCA3Bj1Mp95XXhwyjjdc4bnAphh6JTXbjJfIl 1fDpgDQclhvHNrVjWoIGDCcfUlBoaOIvsTsLBj4r1/hpFBu/wT7GHTJcsQEQyraPtHC6ainJw 3bDRFkM Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Markus Elfring Date: Sat, 12 Dec 2015 12:50:10 +0100 This issue was detected by using the Coccinelle software. A sanity check would be performed by the iscsi_set_default_param() function even if it is known already that the passed variable contained a null pointer. * This implementation detail could be improved by adjustments for jump targets according to the Linux coding style convention. * Let us return directly if a call of the function "kzalloc" failed. Signed-off-by: Markus Elfring --- drivers/target/iscsi/iscsi_target_parameters.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c index 0a8bd3f..15b2618 100644 --- a/drivers/target/iscsi/iscsi_target_parameters.c +++ b/drivers/target/iscsi/iscsi_target_parameters.c @@ -131,20 +131,20 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para if (!param) { pr_err("Unable to allocate memory for parameter.\n"); - goto out; + return NULL; } INIT_LIST_HEAD(¶m->p_list); param->name = kstrdup(name, GFP_KERNEL); if (!param->name) { pr_err("Unable to allocate memory for parameter name.\n"); - goto out; + goto free_param; } param->value = kstrdup(value, GFP_KERNEL); if (!param->value) { pr_err("Unable to allocate memory for parameter value.\n"); - goto out; + goto free_name; } param->phase = phase; @@ -182,18 +182,17 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para default: pr_err("Unknown type_range 0x%02x\n", param->type_range); - goto out; + goto free_value; } list_add_tail(¶m->p_list, ¶m_list->param_list); return param; -out: - if (param) { - kfree(param->value); - kfree(param->name); - kfree(param); - } - +free_value: + kfree(param->value); +free_name: + kfree(param->name); +free_param: + kfree(param); return NULL; }