From 19fd5835f758f0d6341faef7d2f8a6ea6dc55e33 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 11 May 2021 20:29:15 -0500 Subject: [PATCH] samples: sensor: Fix logically dead code in bmg160 sample Converts the bmg160 sample application to check the sensor device at build time instead of runtime. This fixes a Coverity issue for logically dead code introduced in commit 5832e588e3664cc0abb76847ac3a5e4d1954392d. Fixes #35118 Coverity-CID: 235919 Signed-off-by: Maureen Helm --- samples/sensor/bmg160/src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/sensor/bmg160/src/main.c b/samples/sensor/bmg160/src/main.c index 18fbfcf87f0..7201dab4070 100644 --- a/samples/sensor/bmg160/src/main.c +++ b/samples/sensor/bmg160/src/main.c @@ -17,6 +17,10 @@ #define MAX_TEST_TIME 15000 #define SLEEPTIME 300 +#if !DT_HAS_COMPAT_STATUS_OKAY(bosch_bmg160) +#error "No bosch,bmg160 compatible node found in the device tree" +#endif + static void print_gyro_data(const struct device *bmg160) { struct sensor_value val[3]; @@ -173,10 +177,6 @@ void main(void) struct sensor_value attr; #endif - if (!bmg160) { - printf("Device not found.\n"); - return; - } if (!device_is_ready(bmg160)) { printf("Device %s is not ready.\n", bmg160->name); return;