Check rx dma map was allocated before trying to free it, so we don't crash
authorjmatthew <jmatthew@openbsd.org>
Sat, 8 Jul 2023 09:01:30 +0000 (09:01 +0000)
committerjmatthew <jmatthew@openbsd.org>
Sat, 8 Jul 2023 09:01:30 +0000 (09:01 +0000)
if we ran out of memory while bringing the interface up.

tested by hrvoje, ok kevlo@

sys/dev/pci/if_ix.c

index b250ee4..195b5d6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_ix.c,v 1.197 2023/06/01 09:05:33 jan Exp $ */
+/*     $OpenBSD: if_ix.c,v 1.198 2023/07/08 09:01:30 jmatthew Exp $    */
 
 /******************************************************************************
 
@@ -3094,8 +3094,11 @@ ixgbe_free_receive_buffers(struct rx_ring *rxr)
                                m_freem(rxbuf->buf);
                                rxbuf->buf = NULL;
                        }
-                       bus_dmamap_destroy(rxr->rxdma.dma_tag, rxbuf->map);
-                       rxbuf->map = NULL;
+                       if (rxbuf->map != NULL) {
+                               bus_dmamap_destroy(rxr->rxdma.dma_tag,
+                                   rxbuf->map);
+                               rxbuf->map = NULL;
+                       }
                }
                free(rxr->rx_buffers, M_DEVBUF,
                    sc->num_rx_desc * sizeof(struct ixgbe_rx_buf));