From patchwork Sat Jul 14 16:43:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 1198001 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 6F3793FC4C for ; Sat, 14 Jul 2012 16:49:42 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Sq5T8-00087O-Nn; Sat, 14 Jul 2012 16:45:22 +0000 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Sq5S0-00081x-5w for linux-arm-kernel@lists.infradead.org; Sat, 14 Jul 2012 16:45:09 +0000 X-IronPort-AV: E=Sophos;i="4.77,584,1336341600"; d="scan'208";a="150655456" Received: from palace.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Jul 2012 18:43:15 +0200 From: Julia Lawall To: Russell King Subject: [PATCH 3/6] arch/arm/mach-netx/xc.c: ensure a consistent return value in error case Date: Sat, 14 Jul 2012 18:43:05 +0200 Message-Id: <1342284188-19176-4-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1342284188-19176-1-git-send-email-Julia.Lawall@lip6.fr> References: <1342284188-19176-1-git-send-email-Julia.Lawall@lip6.fr> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.134.164.105 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Julia Lawall Typically, the return value desired for the failure of a function with an integer return value is a negative integer. In these cases, the return value is sometimes a negative integer and sometimes 0, due to a subsequent initialization of the return variable within the loop. Resetting ret to 0 at the end of the function is not necessary because the return value of xc_patch is either 0 or a negative integer. A simplified version of the semantic match that finds this problem is: (http://coccinelle.lip6.fr/) // @r exists@ identifier ret; position p; constant C; expression e1,e3,e4; statement S; @@ ret = -C ... when != ret = e3 when any if@p (...) S ... when any if (\(ret != 0\|ret < 0\|ret > 0\) || ...) { ... return ...; } ... when != ret = e3 when any *if@p (...) { ... when != ret = e4 return ret; } // Signed-off-by: Julia Lawall --- If relying on the return value of xc_patch to set ret to 0 is considered too fragile this part of the patch could be dropped. arch/arm/mach-netx/xc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-netx/xc.c b/arch/arm/mach-netx/xc.c index e4cfb7e..18a98e0 100644 --- a/arch/arm/mach-netx/xc.c +++ b/arch/arm/mach-netx/xc.c @@ -149,16 +149,16 @@ int xc_request_firmware(struct xc *x) x->type = head->type; x->version = head->version; - ret = -EINVAL; - for (i = 0; i < 3; i++) { src = fw->data + head->fw_desc[i].ofs; dst = *(unsigned int *)src; src += sizeof (unsigned int); size = head->fw_desc[i].size - sizeof (unsigned int); - if (xc_check_ptr(x, dst, size)) + if (xc_check_ptr(x, dst, size)) { + ret = -EINVAL; goto exit_release_firmware; + } memcpy((void *)io_p2v(dst), src, size); @@ -169,8 +169,6 @@ int xc_request_firmware(struct xc *x) goto exit_release_firmware; } - ret = 0; - exit_release_firmware: release_firmware(fw);