Skip to content

Commit

Permalink
drivers/i2c/meson: fix undefined behaviour
Browse files Browse the repository at this point in the history
In `i2c_load_tokens` we're bit-shifting the value of data by potentially
more than 8-bits which is undefined behaviour in C if data is uint8_t.

To fix this, we can just make data a uint32_t which makes sense since
wdata0 is also uint32_t.

Signed-off-by: Ivan-Velickovic <i.velickovic@unsw.edu.au>
  • Loading branch information
Ivan-Velickovic committed Nov 14, 2024
1 parent 5bd8c6f commit b3d115c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/i2c/meson/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ static inline void i2c_load_tokens(volatile struct i2c_regs *regs)
request_data_offset, tk_offset, wdata_offset, rdata_offset);

// Discover next operation
uint8_t meson_token, data;
uint8_t meson_token;
uint32_t data;
if (i2c_ifState.rw_remaining == 0) {
LOG_DRIVER("Accepting new token...\n");
// Get meson_token if no read/write is in progress.
Expand Down

0 comments on commit b3d115c

Please sign in to comment.