Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2671779lqp; Mon, 25 Mar 2024 06:17:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWq2pHzd4Q0z685app/xq1KuJQOQDUgaawOPaCELUoHNCHIY3tbKGTVvoVLDWF8SgeX0lNi67OVBRm1mFjnTkYa1CKsWi2SDFoEF1e96g== X-Google-Smtp-Source: AGHT+IFAgYizFEajM7EkXhCRCn0wfeqzh+tHEnsOkF+0xOhyvRFPzqERAY+Zo9DMJ1tyAhQ3ZQvB X-Received: by 2002:a17:902:e806:b0:1e0:af99:2a38 with SMTP id u6-20020a170902e80600b001e0af992a38mr7653985plg.45.1711372661278; Mon, 25 Mar 2024 06:17:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711372661; cv=pass; d=google.com; s=arc-20160816; b=ppHY1BwDCZAYwvB+EMpAkBBNlpL5S1tfTWLcasPQ/bxOuVld7r98uQQXLzXE2lN9xH wXo+qOfA4cSXUvAy3MFWVmmQz7HNVr2DRElwPTbxEv95AzI80v1dcGQemwfq7ShjZioV /oDlT6NRta/OS4qqN4SiS0hf8z6JYtKbRRxy9uSGySN9dEfrdoSpwTbXhx5YH9EuH/l1 eOHkM20TU+Je3UVmPlOTVMNffcYZgUT8iz20u045dL4K1Z1VpUSrptM7tmlQd8Lp6bhV GyyQ3J6P3ntQ7LUIREVUKyNveNqjoPxqTaO3lM02dTbUKUFpIJKqeH/cJFXyc6Omeeyu Fcbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=uvoJ1SfOF+NQ4oPj/kzKVhxHX7xSavs0VcaVrMXSZx4=; fh=BCaU6JXa3pVZ41mE9QjZhO/v3FRBoCIKhMJAzPU0Xo8=; b=rbxb9lcCXJ2KY1M1zUOoNELBnFzd2TrikNnogozhFs6tnZozyed6f+rfsNZ/Hs84h9 Jb56cHTtz6jZgxV3WzFsWwqb9MP681CBSVIYFwbPoLNJUVjoige4IwkUeLiuNoHm+1+s OZhM2xlwVcLqAX38vyESTgaTpWmCbI30NL6dbKgMGbJlxVUKmCeJePCG3B27QUZ7Gj0C vQL9nvhA5rocRGLheYONqXQYADiiTLODxrXqBikODaxXn8wekQLGNAuk0z99zlVjrKzQ jU4jEBgLQhicjpggA38u/d7zE0EbJr1Jq/EnhmdqTHMi4EUaSoEktJu7lkICDXD3ap72 xx5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=nfschina.com); spf=pass (google.com: domain of linux-kernel+bounces-116626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116626-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t5-20020a170902e84500b001dddb9f06bfsi5256891plg.479.2024.03.25.06.17.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 06:17:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=nfschina.com); spf=pass (google.com: domain of linux-kernel+bounces-116626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116626-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E3AE92C6548 for ; Mon, 25 Mar 2024 13:16:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E05A1591E0; Mon, 25 Mar 2024 09:37:04 +0000 (UTC) Received: from mail.nfschina.com (unknown [42.101.60.195]) by smtp.subspace.kernel.org (Postfix) with SMTP id B7A803D82DA; Mon, 25 Mar 2024 03:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=42.101.60.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711338124; cv=none; b=MU0kzQRnTDWBEHcK1F/uoAHjjp4uS17lkAwTXNUMzxHoFMG5s/tZE+QKvYnZeGVXDT6bHM6PIS6deSEA0HJKwuegLIyZtpXSPyD5TTRISdn8wNX/1EIS2F+nJor1L1++6DPjch/qyODJ43mJXLYLyR2FXnx/77k3MG0sCIPO31Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711338124; c=relaxed/simple; bh=KGBViHtyWl4RTc5Yv34/CbkultLm1irMrCSdjeeHfsM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gkvEsWa9A6bFiOf7IvQYN4L8r1Opoj0CAZEplhi4HHi4Qu4VJYzzX/Sx1Y+WOtyZkRJ4kDfuVOsfedd13Z6ZCQr3NdIiRqasXlH3auEdQQ2+ERsffpoSrNp06NxMtvKE0M0Sd+r9OytHCPNruTkbMeQVYeMTuK199LZuO5LrTbI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nfschina.com; spf=pass smtp.mailfrom=nfschina.com; arc=none smtp.client-ip=42.101.60.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nfschina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nfschina.com Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPSA id 4E0ED6026BC81; Mon, 25 Mar 2024 11:41:22 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui To: arnaud.pouliquen@foss.st.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, nathan@kernel.org, ndesaulniers@google.com, morbo@google.com, justinstitt@google.com Cc: Su Hui , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, kernel-janitors@vger.kernel.org Subject: [PATCH] ASoC: sti: uniperif: fix the undefined bitwise shift behavior problem Date: Mon, 25 Mar 2024 11:40:33 +0800 Message-Id: <20240325034032.1031885-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Clang static checker(scan-build): sound/soc/sti/uniperif_player.c:1115:12: warning: The result of the left shift is undefined because the right operand is negative [core.UndefinedBinaryOperatorResult] When UNIPERIF_CONFIG_BACK_STALL_REQ_SHIFT(ip) equals to -1, the result of SET_UNIPERIF_CONFIG_BACK_STALL_REQ_DISABLE(ip) is undefined. Here are some results of using different compilers. 1UL >> -1 1UL << -1 gcc 10.2.1 0x2 0 gcc 11.4.0 0 0x8000000000000000 clang 14.0.0 0x64b8a45d72a0 0x64b8a45d72a0 clang 17.0.0 0x556c43b0f2a0 0x556c43b0f2a0 Add some macros to ensure that when right opreand is negative or other invalid values, the results of bitwise shift is zero. Fixes: e1ecace6a685 ("ASoC: sti: Add uniperipheral header file") Signed-off-by: Su Hui --- sound/soc/sti/uniperif.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sound/soc/sti/uniperif.h b/sound/soc/sti/uniperif.h index 2a5de328501c..1cbff01fbff0 100644 --- a/sound/soc/sti/uniperif.h +++ b/sound/soc/sti/uniperif.h @@ -12,17 +12,28 @@ #include +#define SR_SHIFT(a, b) ({unsigned long __a = (a); \ + unsigned int __b = (b); \ + __b < BITS_PER_LONG ? \ + __a >> __b : 0; }) + +#define SL_SHIFT(a, b) ({unsigned long __a = (a); \ + unsigned int __b = (b); \ + __b < BITS_PER_LONG ? \ + __a << __b : 0; }) + /* * Register access macros */ #define GET_UNIPERIF_REG(ip, offset, shift, mask) \ - ((readl_relaxed(ip->base + offset) >> shift) & mask) + (SR_SHIFT(readl_relaxed(ip->base + offset), shift) & mask) #define SET_UNIPERIF_REG(ip, offset, shift, mask, value) \ writel_relaxed(((readl_relaxed(ip->base + offset) & \ - ~(mask << shift)) | (((value) & mask) << shift)), ip->base + offset) + ~SL_SHIFT(mask, shift)) | SL_SHIFT(((value) & mask), shift)),\ + ip->base + offset) #define SET_UNIPERIF_BIT_REG(ip, offset, shift, mask, value) \ - writel_relaxed((((value) & mask) << shift), ip->base + offset) + writel_relaxed(SL_SHIFT(((value) & mask), shift), ip->base + offset) /* * UNIPERIF_SOFT_RST reg -- 2.30.2