From 075cb211e580890d780bb1a0d4b1104bc7874ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Mon, 2 Dec 2024 17:23:46 +0100 Subject: [PATCH] drivers: dac: dacx3608: Fix bad shift operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parameter provided to the `BIT()` macro must be checked so that the shift operation does not overflow the variable. Fixes #81990 Signed-off-by: Martin Jäger --- drivers/dac/dac_dacx3608.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/dac/dac_dacx3608.c b/drivers/dac/dac_dacx3608.c index e2218c6bcdfa..9e783622253e 100644 --- a/drivers/dac/dac_dacx3608.c +++ b/drivers/dac/dac_dacx3608.c @@ -146,7 +146,8 @@ static int dacx3608_write_value(const struct device *dev, uint8_t channel, * Check if channel is initialized * If broadcast channel is used, check if any channel is initialized */ - if ((brdcast && !data->configured) || (!(data->configured & BIT(channel)))) { + if ((brdcast && !data->configured) || + (channel < DACX3608_MAX_CHANNEL && !(data->configured & BIT(channel)))) { LOG_ERR("Channel %d not initialized", channel); return -EINVAL; }