From patchwork Tue Jul 23 15:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 813956 Delivered-To: patch@linaro.org Received: by 2002:adf:f288:0:b0:367:895a:4699 with SMTP id k8csp2367046wro; Tue, 23 Jul 2024 08:15:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUSVQau0fp9WXh3c2W5exevxk2fRjZi+K5SAQJfzh+Ssnp4vWMfXbTx7KzmRFzAH62y80YxS5XK++Hh0i6JriaW X-Google-Smtp-Source: AGHT+IFLSVVcurfHATrDNS0V1HpEOkow8duBG3cIBEgtcHzM5Z1FZC/jFXjIXy7qvQhx1DYGPujA X-Received: by 2002:a05:6808:1b08:b0:3d9:dfef:d7c8 with SMTP id 5614622812f47-3dae9755e33mr11511280b6e.27.1721747721498; Tue, 23 Jul 2024 08:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721747721; cv=none; d=google.com; s=arc-20160816; b=HoYeMf1Ptnbf5mW8Q+BASX9LwgHuvHpf+5EKLukuUCijLG9OGgH7zpeHQ7NkWqNzvA 0QA0KpUdTRT7eOGLCmNvlqVLg54158oabawRrJ+ShsyFR7A9Kj/TO93IPmjbaTDafIlr 9RX9NKwOe08TxIssvi3Up9NuDDXIL0MIpacohULHAuo+A224hxg3xbiad/llgDZ+JvFh 5OR0KKnGEUCgoMJGj3Hw9QRURgQz/qMtoaQxrDhKYWPd66WAYgDfPa72jQXNCVwEoKqK h8apz7PJjUBoUnzrj6QMs8vUKGBI6MO6WUSLM9PTIDq3LMDB3cYjEQF+IFOWKHe/Sn1Q tIaA== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=UWwbuo+0MsX1vzoGfMU7i9YYlVDtQOexa7m/ssopybY=; fh=CYNKLrQn3/SkOzHVC+Oxp/KpGWhDzIr0x67bL1yAbP0=; b=TZTwSDKCwPGJEwj8DLlO81mE78nxEEYfwfDb2i06BuHfIqTZSC5TYoN2X3AKE8UcL1 +/NVYLRNfmtu2G8KDWpXJBM6d3ynyICTK1B94RNap2Zd9ioyP7XG7QjwjaiKRJegcQTX NcwwkvZvCLqQR/tPfYrjrtB9f900zPny9hs1ISlp74FG26uT12j8fSlwHPz45hk/7K4z ZRK7LVRpIQQN+JiaWxbZc1/dPVTVxcRH0/HKy+KxPOARMTxEw6cU9VAkThi1QondZ15I vETi6dlYQm5wk55TwnmsIGHpcWafulIi3yf5lnQu54d+nkaHHhU39V5OPljmb/afLfx7 cAGg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aMq1z/sx"; 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 ada2fe7eead31-493b0de1859si421338137.90.2024.07.23.08.15.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jul 2024 08:15:21 -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="aMq1z/sx"; 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 1sWHEH-0001vn-LY; Tue, 23 Jul 2024 11:15:05 -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 1sWHEB-0001cY-NO for qemu-devel@nongnu.org; Tue, 23 Jul 2024 11:14:59 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sWHE9-0001ti-Qf for qemu-devel@nongnu.org; Tue, 23 Jul 2024 11:14:59 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4267300145eso49104795e9.3 for ; Tue, 23 Jul 2024 08:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721747696; x=1722352496; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UWwbuo+0MsX1vzoGfMU7i9YYlVDtQOexa7m/ssopybY=; b=aMq1z/sx4EoeVsOMG8Gx/uPE116WyNdJZoIOxxz+jRpJX0vUckAjE9yWJShvjUX4c8 M/UX9WyqPGe4rjL0RKfARM5ZolFVxNRWEjDEYhGxZaDgeMqmF2NkHv8wtvSZgRsR0TKz X5W0ruLfPH/qGtbmxxotA8rxzjCriowmOnSisncdhTFjemWXARXB1l0pMUec+w26N0up IcpFACv6bkdaLfLOfJKLyxvr1AOp1oHw1jG6L5lmowVAutmIGaA2KBq+nC9iBCRo7oo7 Ay96QaGfVgt7w7OBT5/YOBtTcJgsbJXJxww6ajVthhOMXwdQQm7+Pz40CtxfFC+ro+Ga 9Ocw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721747696; x=1722352496; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UWwbuo+0MsX1vzoGfMU7i9YYlVDtQOexa7m/ssopybY=; b=RaWr2Sgy2RUqLRTryoG6TX3Quvwx161jD0iinj8gRgk6FYcCnuM3QBi6RcmwouYIjT 48T1Fq2KEPuj4Tb8k4AplCEvZiOg62N33A22he/qrO0qspDruqyts4tL+zV3DP5Sbfza 2orJrGBWUyusByKW9CWzlDDoimUfOWC+7HsKoar9okFP4s9ckZXFAAgxyxBka2+61EE1 8zxyFMd+aTwwRgd+hBUkvwgVKUChSPxwWWHrddxz5kQJY9CDzSdTRPlfXoTR1inssZcC WzMcO/xtaIguUHFK9inuGL4A/vt2NwF5cn2xZOvmDBO5B/BxuUm1FF0gMPVti7Gmsjha lDyQ== X-Gm-Message-State: AOJu0Yzoi/4Soy/Q88FbRX5fphcDj8QJxiveGDh2na6R8cXpGLItFbMb HpwI5VzeAoedqO5T5TLoDbNfoVW/dAQBn7NNGTsOoXbBun+Qn5ZIJLDJbF9lGNYHYBQdzLv828x m X-Received: by 2002:a05:6000:1fa2:b0:368:4def:921a with SMTP id ffacd0b85a97d-369f0a7cab4mr71254f8f.48.1721747695633; Tue, 23 Jul 2024 08:14:55 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-368787ecf92sm11764163f8f.101.2024.07.23.08.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 08:14:55 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Max Filippov Subject: [PATCH] target/xtensa: Make use of 'segment' in pptlb helper less confusing Date: Tue, 23 Jul 2024 16:14:54 +0100 Message-Id: <20240723151454.1396826-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.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=ham 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 Coverity gets confused about the use of the 'segment' variable in the pptlb helper function: it thinks that we can take a code path where we first initialize it: unsigned segment = XTENSA_MPU_PROBE_B; // 0x40000000 and then use that value as a shift count: } else if (nhits == 1 && (env->sregs[MPUENB] & (1u << segment))) { In fact this isn't possible, beacuse xtensa_mpu_lookup() is passed '&segment', and it uses that as an output value, which it will always set if it returns nonzero. But the way the code is currently written is confusing to a human reader as well as to Coverity. Instead of initializing 'segment' at the top of the function with a value that's only used in the "nhits == 0" code path, use the constant value directly in that code path, and don't initialize segment. This matches the way we use xtensa_mpu_lookup() in its other callsites in get_physical_addr_mpu(). Resolves: Coverity CID 1547589 Signed-off-by: Peter Maydell Acked-by: Max Filippov --- target/xtensa/mmu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/xtensa/mmu_helper.c b/target/xtensa/mmu_helper.c index 997b21d3890..29b84d5dbf6 100644 --- a/target/xtensa/mmu_helper.c +++ b/target/xtensa/mmu_helper.c @@ -991,7 +991,7 @@ uint32_t HELPER(rptlb1)(CPUXtensaState *env, uint32_t s) uint32_t HELPER(pptlb)(CPUXtensaState *env, uint32_t v) { unsigned nhits; - unsigned segment = XTENSA_MPU_PROBE_B; + unsigned segment; unsigned bg_segment; nhits = xtensa_mpu_lookup(env->mpu_fg, env->config->n_mpu_fg_segments, @@ -1005,7 +1005,7 @@ uint32_t HELPER(pptlb)(CPUXtensaState *env, uint32_t v) xtensa_mpu_lookup(env->config->mpu_bg, env->config->n_mpu_bg_segments, v, &bg_segment); - return env->config->mpu_bg[bg_segment].attr | segment; + return env->config->mpu_bg[bg_segment].attr | XTENSA_MPU_PROBE_B; } }