Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp273596pxb; Thu, 25 Feb 2021 02:02:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJqc5Wqsfwhwhi3VVZygJyxQFNPcvl6IpE7LaBK3oFPYT0ganLObaS0pRjZ1gZo1z86j6x X-Received: by 2002:a17:906:fa04:: with SMTP id lo4mr1943797ejb.44.1614247361867; Thu, 25 Feb 2021 02:02:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614247361; cv=none; d=google.com; s=arc-20160816; b=B0ZgqhYbYFfGYg0ubfOfsXERnI5aqU4q2SFv3et/zEdRFKEhlfcjTcsPJ7C7VCgIkJ FH1K99UlrbOPQ+WUJngD9jSLNYdg6K3vrZ7z4OAkpwtqr7N2C0DSUX3IhhIezhQgfDHt +duzphPefExOrUd7WG6tP2pumTPqD+qbhXOMIcSqCeosF0yoJV7sNvWEt1B7LS1CN/Sq 0r1OE54JB+EQ7vimIjvw3LmCEphJRAfg874Ce/A1QppeVLZI5yfwNVehHhMKKfJVPF29 VqIec4Pli0WFa8tNakXd1BhzRNOdNgn5an3LyapRBeiIx24RMSm4FrFCepsXYVzO+QAY B1Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=V05U2mHiHNV/IplR2/znYFX+Kvg/9PYfTdSht7eSPhc=; b=DFT2tXXsiMF1o4L01wkO+jpG3jaq2hLExnX2eMM6Rj0TqwgNBV7BtlLmzB9TMlTKYF Q8pK5xZ0j4hZ9mCDHjvcqzARptJCQOUKgn0o3WhZ+jcd0kApJ69r+xaH+O566MMKGXmw Nbun3UVIg9RGuUSoZPVcITnjj6dcHbNsiQ1JCXgroPeW/R2fZUDcSDQWNA2AK7TxL2D1 blgov1ZCUjP7LxQltMQpN446uDZUlr+fNzYHrozLgRvv/nykXm21P9uGToyQAAQuObG5 m6ayTDHQaNFbxtWqC6mNSJCgD8UkO4x7R0vxsj+ridU2jUJvHcZoNAau0XUVkINmsYmY IQGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ln2UawM5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a24si3022543ejy.54.2021.02.25.02.02.19; Thu, 25 Feb 2021 02:02:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ln2UawM5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234853AbhBYJoU (ORCPT + 99 others); Thu, 25 Feb 2021 04:44:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:54678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232723AbhBYJoS (ORCPT ); Thu, 25 Feb 2021 04:44:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D089E64EC3; Thu, 25 Feb 2021 09:43:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614246211; bh=odGN/l6Xb2ytitM63vIjEdZTX1y5B18NzqzfOchHsh4=; h=From:To:Cc:Subject:Date:From; b=Ln2UawM5nhBIhmRdWNcyJi0CABNMIAoVnbUASjMqsHadLUo6Aa2LcMNsvyRWaBbg0 4GaMxu0T0qFNkQjnvTYddbS/v+8uBL04vjEGvM9tY/5qex0jYTqE+twQs8byVewyMX dovDSC25zsAWE84uyLmfX8zD2Z34XLAgjmpxN03bMfMiYYKiuSvdO1whaV8/6I/+QX NqSs5fALDovY1ooE8EpcSEMYqEYE3Uq+0Yrsjt8K/WfCayzFROu41tMky+pbmZ56Qw h55ONofq8SN/zHmAvP6HUX+rybCvpqs08wFm21d01v+jBv/H3+SS9gla/TXgj4Mr9k 3ad+Rj2n4Vnsw== From: Arnd Bergmann To: Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Nathan Chancellor , Nick Desaulniers Cc: Arnd Bergmann , Mike Leach , Leo Yan , Greg Kroah-Hartman , Sai Prakash Ranjan , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH] coresight: etm4x: work around clang-12+ build failure Date: Thu, 25 Feb 2021 10:42:58 +0100 Message-Id: <20210225094324.3542511-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann clang-12 fails to build the etm4x driver with -fsanitize=array-bounds: :1:7: error: expected constant expression in '.inst' directive .inst (0xd5200000|((((2) << 19) | ((1) << 16) | (((((((((((0x160 + (i * 4))))) >> 2))) >> 7) & 0x7)) << 12) | ((((((((((0x160 + (i * 4))))) >> 2))) & 0xf)) << 8) | (((((((((((0x160 + (i * 4))))) >> 2))) >> 4) & 0x7)) << 5)))|(.L__reg_num_x8)) ^ drivers/hwtracing/coresight/coresight-etm4x-core.c:702:4: note: while in macro instantiation etm4x_relaxed_read32(csa, TRCCNTVRn(i)); ^ drivers/hwtracing/coresight/coresight-etm4x.h:403:4: note: expanded from macro 'etm4x_relaxed_read32' read_etm4x_sysreg_offset((offset), false))) ^ drivers/hwtracing/coresight/coresight-etm4x.h:383:12: note: expanded from macro 'read_etm4x_sysreg_offset' __val = read_etm4x_sysreg_const_offset((offset)); \ ^ drivers/hwtracing/coresight/coresight-etm4x.h:149:2: note: expanded from macro 'read_etm4x_sysreg_const_offset' READ_ETM4x_REG(ETM4x_OFFSET_TO_REG(offset)) ^ drivers/hwtracing/coresight/coresight-etm4x.h:144:2: note: expanded from macro 'READ_ETM4x_REG' read_sysreg_s(ETM4x_REG_NUM_TO_SYSREG((reg))) ^ arch/arm64/include/asm/sysreg.h:1108:15: note: expanded from macro 'read_sysreg_s' asm volatile(__mrs_s("%0", r) : "=r" (__val)); \ ^ arch/arm64/include/asm/sysreg.h:1074:2: note: expanded from macro '__mrs_s' " mrs_s " v ", " __stringify(r) "\n" \ ^ It appears that the __builin_constant_p() check in read_etm4x_sysreg_offset() falsely returns 'true' here because clang decides finds that an out-of-bounds access to config->cntr_val[] cannot happen, and then it unrolls the loop with constant register numbers. Then when actually emitting the output, it fails to figure out the value again. While this is incorrect behavior in clang, it is easy to work around by avoiding the out-of-bounds array access. Do this by limiting the loop counter to the actual dimension of the array. Link: https://github.com/ClangBuiltLinux/linux/issues/1310 Signed-off-by: Arnd Bergmann --- drivers/hwtracing/coresight/coresight-etm4x-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c index 15016f757828..4cccf874a602 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c @@ -691,13 +691,13 @@ static void etm4_disable_hw(void *info) "timeout while waiting for PM stable Trace Status\n"); /* read the status of the single shot comparators */ - for (i = 0; i < drvdata->nr_ss_cmp; i++) { + for (i = 0; i < min_t(u32, drvdata->nr_ss_cmp, ETM_MAX_SS_CMP); i++) { config->ss_status[i] = etm4x_relaxed_read32(csa, TRCSSCSRn(i)); } /* read back the current counter values */ - for (i = 0; i < drvdata->nr_cntr; i++) { + for (i = 0; i < min_t(u32, drvdata->nr_cntr, ETMv4_MAX_CNTR); i++) { config->cntr_val[i] = etm4x_relaxed_read32(csa, TRCCNTVRn(i)); } -- 2.29.2