Skip to content

Commit

Permalink
drivers: dac: dacx3608: Fix bad shift operation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
martinjaeger authored and kartben committed Jan 7, 2025
1 parent b1212a9 commit 075cb21
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/dac/dac_dacx3608.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 075cb21

Please sign in to comment.