From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX5iw-0003Sv-Vj for qemu-devel@nongnu.org; Sat, 20 Feb 2016 06:29:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX5iw-00070M-3U for qemu-devel@nongnu.org; Sat, 20 Feb 2016 06:29:18 -0500 Received: from mail-vk0-x231.google.com ([2607:f8b0:400c:c05::231]:36630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX5iv-0006zj-KA for qemu-devel@nongnu.org; Sat, 20 Feb 2016 06:29:18 -0500 Received: by mail-vk0-x231.google.com with SMTP id c3so95642406vkb.3 for ; Sat, 20 Feb 2016 03:29:17 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <1455892784-11328-1-git-send-email-peter.maydell@linaro.org> <1455892784-11328-3-git-send-email-peter.maydell@linaro.org> From: Peter Maydell Date: Sat, 20 Feb 2016 11:28:57 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH v2 2/2] target-arm: Implement MDCR_EL3.TPM and MDCR_EL2.TPM traps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alistair Francis Cc: "Edgar E. Iglesias" , qemu-arm , "qemu-devel@nongnu.org Developers" , Patch Tracking , Sergey Fedorov On 19 February 2016 at 19:38, Alistair Francis wrote: > On Fri, Feb 19, 2016 at 6:39 AM, Peter Maydell wrote: >> +/* Check for traps to performance monitor registers, which are controlled >> + * by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3. >> + */ >> +static CPAccessResult access_tpm(CPUARMState *env, const ARMCPRegInfo *ri, >> + bool isread) >> +{ >> + int el = arm_current_el(env); >> + >> + if (el < 2 && (env->cp15.mdcr_el2 & MDCR_TPM) >> + && !arm_is_secure_below_el3(env)) { >> + return CP_ACCESS_TRAP_EL2; >> + } >> + if (el < 3 && (env->cp15.mdcr_el3 & MDCR_TPM)) { >> + return CP_ACCESS_TRAP_EL3; >> + } > > Hey Peter, > > Why not use else if? I generally tend not to use else-if ladders if the thing in the conditional returns unconditionally, just as a personal style preference. "if () { X } else if () { Y } Z" implies a possible control flow path of "take the if branch so run X, then skip Y, and continue after to run Z", and if X returns unconditionally that can't happen. It also matches up with the usual approach of if (something) { early return; } main body of function; which you wouldn't want to write as if (something) { early return; } else { main body; } thanks -- PMM