lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240325034032.1031885-1-suhui@nfschina.com>
Date: Mon, 25 Mar 2024 11:40:33 +0800
From: Su Hui <suhui@...china.com>
To: arnaud.pouliquen@...s.st.com,
	lgirdwood@...il.com,
	broonie@...nel.org,
	perex@...ex.cz,
	tiwai@...e.com,
	nathan@...nel.org,
	ndesaulniers@...gle.com,
	morbo@...gle.com,
	justinstitt@...gle.com
Cc: Su Hui <suhui@...china.com>,
	alsa-devel@...a-project.org,
	linux-sound@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	llvm@...ts.linux.dev,
	kernel-janitors@...r.kernel.org
Subject: [PATCH] ASoC: sti: uniperif: fix the undefined bitwise shift behavior problem

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 <suhui@...china.com>
---
 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 <sound/dmaengine_pcm.h>
 
+#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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ