Skip to content

Commit

Permalink
gpio: sx1509b: Fix address-of-packed-mem warning
Browse files Browse the repository at this point in the history
The warning below appears once -Waddress-of-packed-mem is enabled:

/__w/zephyr/zephyr/drivers/gpio/gpio_sx1509b.c: In function
'port_write':
/__w/zephyr/zephyr/drivers/gpio/gpio_sx1509b.c:456:19: error: taking
address of packed member of 'struct sx1509b_pin_state' may result in an
unaligned pointer value [-Werror=address-of-packed-member]
  456 |  uint16_t *outp = &drv_data->pin_state.data;

To avoid the warning, use an intermediate void * variable.

More info in zephyrproject-rtos#16587.

Signed-off-by: Carles Cufi <[email protected]>
  • Loading branch information
carlescufi committed Dec 10, 2021
1 parent 4f64ae3 commit 710e03b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/gpio/gpio_sx1509b.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ static int port_write(const struct device *dev,

const struct sx1509b_config *cfg = dev->config;
struct sx1509b_drv_data *drv_data = dev->data;
uint16_t *outp = &drv_data->pin_state.data;
void *data = &drv_data->pin_state.data;
uint16_t *outp = data;

__ASSERT_NO_MSG(IS_PTR_ALIGNED(data, uint16_t));

k_sem_take(&drv_data->lock, K_FOREVER);

Expand Down

0 comments on commit 710e03b

Please sign in to comment.