zephyr/drivers/sensor/bmi160
Avi Green a2190cc92b bmi160: bmi160_bus union bugfix
bmi160.c module defines DT_DRV_COMPAT, but bmi160_trigger.c doesn't.
This causes a catastrophic chain of events.
The bmi160.c module includes bmi160.h,
in which the macro DT_ANY_INST_ON_BUS_STATUS_OKAY
affects the size of bmi160_bus union.
So bmi160.c defines a bmi160_cfg struct which contains that union.
Now, in bmi160_trigger_init we get a pointer to that config struct.
The fact that this module now includes bmi160.h without
DT_DRV_COMPAT, causes it to think the union is empty.

That doesn't cause compilation error, just undefined behaviour,
In which you address an empty struct fields.

In general, I suggest that someone makes sure it doesn't happen
in other drivers as well. The problem presented here is general,
meaning that if an h file assumes someone defined DT_DRV_COMPAT
before and it doesn't,
it may lead to some weird behaviour, like the one described.

Signed-off-by: Avi Green <avigreen1978@yandex.com>
2022-03-11 07:05:12 -06:00
..
bmi160_trigger.c drivers: sensor: drop get_dev_data/get_dev_config usage 2022-01-19 18:16:02 +01:00
bmi160.c bmi160: bmi160_bus union bugfix 2022-03-11 07:05:12 -06:00
bmi160.h bmi160: bmi160_bus union bugfix 2022-03-11 07:05:12 -06:00
CMakeLists.txt drivers: sensor: clean up zephyr_library calls 2021-06-30 09:36:33 -04:00
Kconfig