samples: sensor: Fix logically dead code in adxl372 sample
Converts the adxl372 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 72795c3e6c2949961d0bf78bcfe94ca75f399d44.
Fixes #35119
Coverity-CID: 235932
Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
diff --git a/samples/sensor/adxl372/src/main.c b/samples/sensor/adxl372/src/main.c
index 6ad1cc4..934a9bb 100644
--- a/samples/sensor/adxl372/src/main.c
+++ b/samples/sensor/adxl372/src/main.c
@@ -10,6 +10,10 @@
#define pow2(x) ((x) * (x))
+#if !DT_HAS_COMPAT_STATUS_OKAY(adi_adxl372)
+#error "No adi,adxl372 compatible node found in the device tree"
+#endif
+
static double sqrt(double value)
{
int i;
@@ -50,10 +54,6 @@
const struct device *dev = DEVICE_DT_GET_ANY(adi_adxl372);
- if (!dev) {
- printf("Devicetree has no adi,adxl372 node\n");
- return;
- }
if (!device_is_ready(dev)) {
printf("Device %s is not ready\n", dev->name);
return;