From 8cfef933d705986705f40c747d5a1de4b6feaca0 Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Mon, 6 Apr 2020 14:25:32 +0200 Subject: [PATCH] drivers: lora: sx1276: handle NULL callback in irqHandlers Part of sx1276 driver which is in loramac-node module passes to Zephyr irqHandlers with callbacks. Some of those callbacks can be NULL and this is true now (with the current version of loramac-node) for DIO5. If we define all 0-5 DIOs in dts, then this results in interrupts which are unwanted. As we do not check that loramac-node callback is NULL, then we crash trying to call it. Check every handler during initialization and just skip initialization of GPIO if it is NULL. This also prevents crashes, because there is no way GPIO interrupt to be triggered in runtime for this DIO. Signed-off-by: Marcin Niestroj --- drivers/lora/sx1276.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/lora/sx1276.c b/drivers/lora/sx1276.c index 1977cc57dc6..3f429e791a2 100644 --- a/drivers/lora/sx1276.c +++ b/drivers/lora/sx1276.c @@ -177,6 +177,10 @@ void SX1276IoIrqInit(DioIrqHandler **irqHandlers) /* Setup DIO gpios */ for (i = 0; i < SX1276_MAX_DIO; i++) { + if (!irqHandlers[i]) { + continue; + } + dev_data.dio_dev[i] = device_get_binding(sx1276_dios[i].port); if (dev_data.dio_dev[i] == NULL) { LOG_ERR("Cannot get pointer to %s device",