sensor: bmi160: Fix address-of-packed-mem warning

The warning below appears once -Waddress-of-packed-mem is enabled:

/__w/zephyr/zephyr/drivers/sensor/bmi160/bmi160.c: In function
bmi160_gyr_channel_get:
/__w/zephyr/zephyr/drivers/sensor/bmi160/bmi160.c:795:23: error: taking
address of packed member of struct <anonymous> may result in an
unaligned pointer value [-Werror=address-of-packed-member]
  795 |           data->sample.gyr, val);
      |           ~~~~~~~~~~~~^~~~
/__w/zephyr/zephyr/drivers/sensor/bmi160/bmi160.c: In function
bmi160_acc_channel_get:
/__w/zephyr/zephyr/drivers/sensor/bmi160/bmi160.c:807:23: error: taking
address of packed member of struct <anonymous> may result in an
unaligned pointer value [-Werror=address-of-packed-member]
  807 |           data->sample.acc, val);
      |           ~~~~~~~~~~~~^~~~

To avoid the warning, make the struct non-packed, since it is not
necessary in this case given that a union already guarantees that the
pointer to the union points to each member of the union equally..

More info in #16587.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
Carles Cufi 2021-12-08 14:09:40 +01:00 committed by Carles Cufí
commit 2bc9cb4691
2 changed files with 3 additions and 5 deletions

View file

@ -791,8 +791,7 @@ static inline void bmi160_gyr_channel_get(const struct device *dev,
{
struct bmi160_data *data = to_data(dev);
bmi160_channel_convert(chan, data->scale.gyr,
data->sample.gyr, val);
bmi160_channel_convert(chan, data->scale.gyr, data->sample.gyr, val);
}
#endif
@ -803,8 +802,7 @@ static inline void bmi160_acc_channel_get(const struct device *dev,
{
struct bmi160_data *data = to_data(dev);
bmi160_channel_convert(chan, data->scale.acc,
data->sample.acc, val);
bmi160_channel_convert(chan, data->scale.acc, data->sample.acc, val);
}
#endif

View file

@ -471,7 +471,7 @@ union bmi160_sample {
#if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND)
uint16_t acc[BMI160_AXES];
#endif
} __packed;
};
};
struct bmi160_scale {