From e90f154cac6bbcfb4428c2edfc6f05e49c446d98 Mon Sep 17 00:00:00 2001 From: Fabian Montero Date: Fri, 18 Oct 2024 23:28:41 -0600 Subject: [PATCH] fix kernel panic --- lora_sx127.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lora_sx127.c b/lora_sx127.c index 381a05b..9cafe97 100644 --- a/lora_sx127.c +++ b/lora_sx127.c @@ -441,7 +441,7 @@ exit_busy: static void sx127x_poll_work(struct work_struct *work) { - u8 ack_flags, lqi, mode, read_flags, rx_base, *rx_data, rx_length; + u8 ack_flags, lqi, mode, read_flags, rx_base, *rx_data, rx_length = 0; bool do_rx = false, was_busy = false; unsigned long spin_irq; struct sx127x *hw = container_of(work, struct sx127x, poll_work); @@ -492,15 +492,19 @@ static void sx127x_poll_work(struct work_struct *work) if (sx127x_reg_write(hw, SX127X_REG_FIFO_ADDR_PTR, rx_base) < 0) goto exit_busy; - rx_skb = dev_alloc_skb(IEEE802154_MTU); - if (!rx_skb) - goto exit_busy; - - rx_data = skb_put(rx_skb, rx_length); - while (rx_length--) - if (sx127x_reg_read(hw, SX127X_REG_FIFO, rx_data++) < 0) + if (rx_length <= IEEE802154_MTU) { + rx_skb = dev_alloc_skb(IEEE802154_MTU); + if (!rx_skb) goto exit_busy; + rx_data = skb_put(rx_skb, rx_length); + + while (rx_length--) + if (sx127x_reg_read(hw, SX127X_REG_FIFO, rx_data++) < 0) + goto exit_busy; + } else + dev_err(&hw->spi->dev, "%s: rx_length overflow: %u > IEEE802154_MTU\n", __func__, rx_length); + if (sx127x_reg_write(hw, SX127X_REG_FIFO_RX_BASE_ADDR, SX127X_FIFO_RX_BASE_ADDRESS) < 0) goto exit_busy; }