Skip to content

Commit 2bc9cb4

Browse files
committed
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 <[email protected]>
1 parent 0b96dd4 commit 2bc9cb4

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

drivers/sensor/bmi160/bmi160.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,7 @@ static inline void bmi160_gyr_channel_get(const struct device *dev,
791791
{
792792
struct bmi160_data *data = to_data(dev);
793793

794-
bmi160_channel_convert(chan, data->scale.gyr,
795-
data->sample.gyr, val);
794+
bmi160_channel_convert(chan, data->scale.gyr, data->sample.gyr, val);
796795
}
797796
#endif
798797

@@ -803,8 +802,7 @@ static inline void bmi160_acc_channel_get(const struct device *dev,
803802
{
804803
struct bmi160_data *data = to_data(dev);
805804

806-
bmi160_channel_convert(chan, data->scale.acc,
807-
data->sample.acc, val);
805+
bmi160_channel_convert(chan, data->scale.acc, data->sample.acc, val);
808806
}
809807
#endif
810808

drivers/sensor/bmi160/bmi160.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ union bmi160_sample {
471471
#if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND)
472472
uint16_t acc[BMI160_AXES];
473473
#endif
474-
} __packed;
474+
};
475475
};
476476

477477
struct bmi160_scale {

0 commit comments

Comments
 (0)