[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241105140359.2465656-3-quzicheng@huawei.com>
Date: Tue, 5 Nov 2024 14:03:59 +0000
From: Zicheng Qu <quzicheng@...wei.com>
To: <lars@...afoo.de>, <Michael.Hennerich@...log.com>, <jic23@...nel.org>,
<gregkh@...uxfoundation.org>, <cristina.opriceana@...il.com>,
<daniel.baluta@...el.com>, <linux-iio@...r.kernel.org>,
<linux-staging@...ts.linux.dev>, <linux-kernel@...r.kernel.org>
CC: <tanghui20@...wei.com>, <zhangqiao22@...wei.com>,
<judy.chenhui@...wei.com>, <quzicheng@...wei.com>
Subject: [PATCH 2/2] staging: iio: ad9832: Correct phase range check
The phase register for the AD9832 is 12 bits, which means the valid
phase values range from 0 to 4095 (2^12 - 1). The current check uses a
greater-than condition with BIT(12), which equals 4096. This allows an
invalid phase value of 4096 to pass.
This patch corrects the check to use greater-than-or-equal-to, ensuring
that only phase values within the valid range are accepted.
Fixes: f1d05b5f68cb ("Staging: iio: Prefer using the BIT macro")
Cc: <stable@...r.kernel.org>
Signed-off-by: Zicheng Qu <quzicheng@...wei.com>
---
drivers/staging/iio/frequency/ad9832.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/iio/frequency/ad9832.c b/drivers/staging/iio/frequency/ad9832.c
index 492612e8f8ba..140ee4f9c137 100644
--- a/drivers/staging/iio/frequency/ad9832.c
+++ b/drivers/staging/iio/frequency/ad9832.c
@@ -158,7 +158,7 @@ static int ad9832_write_frequency(struct ad9832_state *st,
static int ad9832_write_phase(struct ad9832_state *st,
unsigned long addr, unsigned long phase)
{
- if (phase > BIT(AD9832_PHASE_BITS))
+ if (phase >= BIT(AD9832_PHASE_BITS))
return -EINVAL;
st->phase_data[0] = cpu_to_be16((AD9832_CMD_PHA8BITSW << CMD_SHIFT) |
--
2.34.1
Powered by blists - more mailing lists