From patchwork Tue Jul 23 13:10:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 813949 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2309300wro; Tue, 23 Jul 2024 06:12:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXQeO0RwSb7NSw+jgRwlvQppF+0D5gwemoct3PjRA7pOjiIbS8ippKjCTm1UgikdN/rHE5TADM6vJd+ttrSGuU6 X-Google-Smtp-Source: AGHT+IGKFyeHc0tH8GlxFX+kuvqyUN8Q4F8Ixt5q28gbXgOhmvb8H3LIenrNhGcYaTFaxJLTPxiO X-Received: by 2002:a05:6830:6784:b0:703:64ad:83e7 with SMTP id 46e09a7af769-709009e18famr12784545a34.30.1721740336254; Tue, 23 Jul 2024 06:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721740336; cv=none; d=google.com; s=arc-20160816; b=Dw6OnumpX8ZXccQvVdXjPQUGnX1ZDEv1su+GGjCFIT36DWBz59AN0uY66RumrUv4p1 nII6sPhrqgulgLuWtWErXAwTpVL0M9zntVZoeYC5jOA4iYAaPWtJGZjTWgmn/AtdwAqy ga01fEPgPj/fmCdrgxJ7a9j0NX74zF54UI1BFcr2kQej0yaCFHi+Af7Lh7UyxSYdCGm9 sTlZEgZPtInqkKJyy7G6di5igsmhL3mX7uN9mE4AtVHjY+fLNKDu9r/QJ7W9K5DPls/A ABl90icAfLX5BkUzoVRt5pL00DujjMYAXwD0cjJCf5ALmRizQglTS1B0WANJpbZxcdhn DFwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9E2PaL3j+vd9cDXCmCuxFcqlpV5vqk14FssyzTSrOZg=; fh=E7xCcyEriYH+R7slwpFJEqLV8/ADpzTfVfPlRKbLzIo=; b=Ic12+IDTzdWyuD4xqRfUdaJNZKfCmf3K7wSEoGVqYzm/m2MkIXiBzjnOhaDBpi2Zcr 8vPYCa0dcdQlWo0Fb6xLaHnKbNSMeoBqGs7EAl45D0TEZbo4FAbI5+2Vpej1naLDW1hk LPJHI0Y9Q6n3MkeutdQDV1CAZTxgNTdrIIMSvye1LhMUdgqtIC/d55T1YZU7t0qydzXm v9yUYsGlxop7oPdrjraD3auGOSk0mJ+HPbK0NZtfjuWwVQf3n0ttDIe20Xe/TyVY3+EG JaSLa5XD2zDJB8bVln8VRo50cL2WJTId7FU7gtDmuO60qCX9seLYKh6+a76ymjfm+eRA CcMA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kZGaOpVu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a1e0cc1a2514c-826e10927f9si1245186241.176.2024.07.23.06.12.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2024 06:12:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kZGaOpVu; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sWFHv-0006H3-Ai; Tue, 23 Jul 2024 09:10:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sWFHt-00068o-DT for qemu-devel@nongnu.org; Tue, 23 Jul 2024 09:10:41 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWFHp-0000JD-8i for qemu-devel@nongnu.org; Tue, 23 Jul 2024 09:10:41 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-52efc89dbedso2955585e87.3 for ; Tue, 23 Jul 2024 06:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721740234; x=1722345034; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9E2PaL3j+vd9cDXCmCuxFcqlpV5vqk14FssyzTSrOZg=; b=kZGaOpVuBAkbvhXWcHHAwlkKHgia25On/j2OTsM42IDzh7OUrikyYn8pFgdvOJgM/d ZZnb6k7UWVWYVaOgAV2aa6hNtoaQsmV+NvPXUb+x4wzyB6gvAYb0X/kcU5rjr6dcMauB HV/L4Fog5E52NrKsrAY0ZDGxL1+RIVggGHf8atbffek6vfFDbHpd+sQUPdgEn4gXaF9b bEtnDUuYhz6IxlO1NTqfMI2Q13HvDCzhC+8egr043WOOMX6vZVAhAMocw2cflybGS9bN mnERjNXZisIg8X4AOGWA5JRRtXfITynnYaCxI8gWx6P4ii7b5QFA/Ao+O47A+MO9sOp6 e9QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721740234; x=1722345034; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9E2PaL3j+vd9cDXCmCuxFcqlpV5vqk14FssyzTSrOZg=; b=myc3aeA0dNdtTuoqeltTU7B0jd0Zl+YtdLafdBrXG2Be+bvnTRAK1b/DGkgkpbwQvx /LH1Yt3CkS7rUl6u3raVcK98R7KH0SXO68trR5ELglGxkJgnObdCeNxzduByapK7xnbp 3XB+VbEOQe0xmYAh+2IGZShg3qj1TC+nABVeS6aKd0pQdMqiGRu3MstMNEA6OWYCPe9/ 3mkvtI2ETaD60VXE12ITacvmyIjAO5qvW1ObMq09MI1Ty4oypuwJlOLCMmijeXAh/jNl eVBmdFs23HJ549vZ6Vcc+p3UL1ROFBm4pSkRzSRYwCLgyoSXYRWurvzlQXhYoEuaJ5ax PRSQ== X-Forwarded-Encrypted: i=1; AJvYcCW9l759e9vfs2fbL6BoKk7+oFvv7IiHzDLJ14qtj760cV4MAV6NFz8glomIkAFrOwOPxsVJJH+mz96uR36RPU+gK1Wnz+Y= X-Gm-Message-State: AOJu0YzjdtRssDQEBLWqbhW3Fb7Tvs/C6zsVZQpBocWJijFOBSOcT8v/ +aLji8dhVj16Ymmyb+Rr57g9h8m8Jo+ex28nGn6B6V44LFP4//1cdAsBdI6o+tE= X-Received: by 2002:a05:6512:31d5:b0:52e:97dd:327b with SMTP id 2adb3069b0e04-52fc4047a95mr2439492e87.23.1721740234156; Tue, 23 Jul 2024 06:10:34 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36878684773sm11560157f8f.7.2024.07.23.06.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 06:10:32 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH 3/4] hw/misc/bcm2835_property: Restrict scope of start_num, number, otp_row Date: Tue, 23 Jul 2024 14:10:28 +0100 Message-Id: <20240723131029.1159908-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240723131029.1159908-1-peter.maydell@linaro.org> References: <20240723131029.1159908-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=peter.maydell@linaro.org; helo=mail-lf1-x135.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In the long function bcm2835_property_mbox_push(), the variables start_num, number and otp_row are used only in the four cases which access OTP data, and their uses don't overlap with each other. Make these variables have scope restricted to the cases where they're used, so it's easier to read each individual case without having to cross-refer up to the variable declaration at the top of the function and check whether the variable is also used later in the loop. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/misc/bcm2835_property.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c index 7eb623b4e90..443d42a1824 100644 --- a/hw/misc/bcm2835_property.c +++ b/hw/misc/bcm2835_property.c @@ -30,7 +30,6 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) uint32_t tot_len; size_t resplen; uint32_t tmp; - uint32_t start_num, number, otp_row; /* * Copy the current state of the framebuffer config; we will update @@ -331,22 +330,25 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) /* Customer OTP */ case RPI_FWREQ_GET_CUSTOMER_OTP: - start_num = ldl_le_phys(&s->dma_as, value + 12); - number = ldl_le_phys(&s->dma_as, value + 16); + { + uint32_t start_num = ldl_le_phys(&s->dma_as, value + 12); + uint32_t number = ldl_le_phys(&s->dma_as, value + 16); resplen = 8 + 4 * number; for (uint32_t n = start_num; n < start_num + number && n < BCM2835_OTP_CUSTOMER_OTP_LEN; n++) { - otp_row = bcm2835_otp_get_row(s->otp, + uint32_t otp_row = bcm2835_otp_get_row(s->otp, BCM2835_OTP_CUSTOMER_OTP + n); stl_le_phys(&s->dma_as, value + 20 + ((n - start_num) << 2), otp_row); } break; + } case RPI_FWREQ_SET_CUSTOMER_OTP: - start_num = ldl_le_phys(&s->dma_as, value + 12); - number = ldl_le_phys(&s->dma_as, value + 16); + { + uint32_t start_num = ldl_le_phys(&s->dma_as, value + 12); + uint32_t number = ldl_le_phys(&s->dma_as, value + 16); resplen = 4; @@ -367,32 +369,35 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) for (uint32_t n = start_num; n < start_num + number && n < BCM2835_OTP_CUSTOMER_OTP_LEN; n++) { - otp_row = ldl_le_phys(&s->dma_as, + uint32_t otp_row = ldl_le_phys(&s->dma_as, value + 20 + ((n - start_num) << 2)); bcm2835_otp_set_row(s->otp, BCM2835_OTP_CUSTOMER_OTP + n, otp_row); } break; + } /* Device-specific private key */ - case RPI_FWREQ_GET_PRIVATE_KEY: - start_num = ldl_le_phys(&s->dma_as, value + 12); - number = ldl_le_phys(&s->dma_as, value + 16); + { + uint32_t start_num = ldl_le_phys(&s->dma_as, value + 12); + uint32_t number = ldl_le_phys(&s->dma_as, value + 16); resplen = 8 + 4 * number; for (uint32_t n = start_num; n < start_num + number && n < BCM2835_OTP_PRIVATE_KEY_LEN; n++) { - otp_row = bcm2835_otp_get_row(s->otp, + uint32_t otp_row = bcm2835_otp_get_row(s->otp, BCM2835_OTP_PRIVATE_KEY + n); stl_le_phys(&s->dma_as, value + 20 + ((n - start_num) << 2), otp_row); } break; + } case RPI_FWREQ_SET_PRIVATE_KEY: - start_num = ldl_le_phys(&s->dma_as, value + 12); - number = ldl_le_phys(&s->dma_as, value + 16); + { + uint32_t start_num = ldl_le_phys(&s->dma_as, value + 12); + uint32_t number = ldl_le_phys(&s->dma_as, value + 16); resplen = 4; @@ -404,12 +409,13 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value) for (uint32_t n = start_num; n < start_num + number && n < BCM2835_OTP_PRIVATE_KEY_LEN; n++) { - otp_row = ldl_le_phys(&s->dma_as, + uint32_t otp_row = ldl_le_phys(&s->dma_as, value + 20 + ((n - start_num) << 2)); bcm2835_otp_set_row(s->otp, BCM2835_OTP_PRIVATE_KEY + n, otp_row); } break; + } default: qemu_log_mask(LOG_UNIMP, "bcm2835_property: unhandled tag 0x%08x\n", tag);