Module Name: src Committed By: msaitoh Date: Tue Jan 21 14:55:55 UTC 2020
Modified Files: src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h ixgbe_netbsd.c ixv.c Log Message: Fix the freeing code for some error paths. Found and tested by Patrick Welche. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sys/dev/pci/ixgbe/ix_txrx.c cvs rdiff -u -r1.220 -r1.221 src/sys/dev/pci/ixgbe/ixgbe.c cvs rdiff -u -r1.61 -r1.62 src/sys/dev/pci/ixgbe/ixgbe.h cvs rdiff -u -r1.11 -r1.12 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c cvs rdiff -u -r1.143 -r1.144 src/sys/dev/pci/ixgbe/ixv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/ixgbe/ix_txrx.c diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.59 src/sys/dev/pci/ixgbe/ix_txrx.c:1.60 --- src/sys/dev/pci/ixgbe/ix_txrx.c:1.59 Mon Jan 20 07:19:04 2020 +++ src/sys/dev/pci/ixgbe/ix_txrx.c Tue Jan 21 14:55:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ix_txrx.c,v 1.59 2020/01/20 07:19:04 msaitoh Exp $ */ +/* $NetBSD: ix_txrx.c,v 1.60 2020/01/21 14:55:55 msaitoh Exp $ */ /****************************************************************************** @@ -2353,3 +2353,24 @@ err_tx_desc: free(adapter->queues, M_DEVBUF); return (error); } /* ixgbe_allocate_queues */ + +/************************************************************************ + * ixgbe_free_queues + * + * Free descriptors for the transmit and receive rings, and then + * the memory associated with each. + ************************************************************************/ +void +ixgbe_free_queues(struct adapter *adapter) +{ + struct ix_queue *que; + int i; + + ixgbe_free_transmit_structures(adapter); + ixgbe_free_receive_structures(adapter); + for (i = 0; i < adapter->num_queues; i++) { + que = &adapter->queues[i]; + mutex_destroy(&que->dc_mtx); + } + free(adapter->queues, M_DEVBUF); +} /* ixgbe_free_queues */ Index: src/sys/dev/pci/ixgbe/ixgbe.c diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.220 src/sys/dev/pci/ixgbe/ixgbe.c:1.221 --- src/sys/dev/pci/ixgbe/ixgbe.c:1.220 Fri Jan 3 12:59:46 2020 +++ src/sys/dev/pci/ixgbe/ixgbe.c Tue Jan 21 14:55:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ixgbe.c,v 1.220 2020/01/03 12:59:46 pgoyette Exp $ */ +/* $NetBSD: ixgbe.c,v 1.221 2020/01/21 14:55:55 msaitoh Exp $ */ /****************************************************************************** @@ -1059,9 +1059,7 @@ ixgbe_attach(device_t parent, device_t d error = ixgbe_allocate_msix(adapter, pa); if (error) { /* Free allocated queue structures first */ - ixgbe_free_transmit_structures(adapter); - ixgbe_free_receive_structures(adapter); - free(adapter->queues, M_DEVBUF); + ixgbe_free_queues(adapter); /* Fallback to legacy interrupt */ adapter->feat_en &= ~IXGBE_FEATURE_MSIX; @@ -1236,9 +1234,7 @@ ixgbe_attach(device_t parent, device_t d return; err_late: - ixgbe_free_transmit_structures(adapter); - ixgbe_free_receive_structures(adapter); - free(adapter->queues, M_DEVBUF); + ixgbe_free_queues(adapter); err_out: ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); ctrl_ext &= ~IXGBE_CTRL_EXT_DRV_LOAD; @@ -3712,13 +3708,7 @@ ixgbe_detach(device_t dev, int flags) evcnt_detach(&stats->ptc1023); evcnt_detach(&stats->ptc1522); - ixgbe_free_transmit_structures(adapter); - ixgbe_free_receive_structures(adapter); - for (i = 0; i < adapter->num_queues; i++) { - struct ix_queue * que = &adapter->queues[i]; - mutex_destroy(&que->dc_mtx); - } - free(adapter->queues, M_DEVBUF); + ixgbe_free_queues(adapter); free(adapter->mta, M_DEVBUF); IXGBE_CORE_LOCK_DESTROY(adapter); Index: src/sys/dev/pci/ixgbe/ixgbe.h diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.61 src/sys/dev/pci/ixgbe/ixgbe.h:1.62 --- src/sys/dev/pci/ixgbe/ixgbe.h:1.61 Mon Jan 20 07:19:04 2020 +++ src/sys/dev/pci/ixgbe/ixgbe.h Tue Jan 21 14:55:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ixgbe.h,v 1.61 2020/01/20 07:19:04 msaitoh Exp $ */ +/* $NetBSD: ixgbe.h,v 1.62 2020/01/21 14:55:55 msaitoh Exp $ */ /****************************************************************************** SPDX-License-Identifier: BSD-3-Clause @@ -768,6 +768,7 @@ void ixgbe_deferred_mq_start_work(struct void ixgbe_drain_all(struct adapter *); int ixgbe_allocate_queues(struct adapter *); +void ixgbe_free_queues(struct adapter *); int ixgbe_setup_transmit_structures(struct adapter *); void ixgbe_free_transmit_structures(struct adapter *); int ixgbe_setup_receive_structures(struct adapter *); Index: src/sys/dev/pci/ixgbe/ixgbe_netbsd.c diff -u src/sys/dev/pci/ixgbe/ixgbe_netbsd.c:1.11 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c:1.12 --- src/sys/dev/pci/ixgbe/ixgbe_netbsd.c:1.11 Mon Jan 20 07:19:04 2020 +++ src/sys/dev/pci/ixgbe/ixgbe_netbsd.c Tue Jan 21 14:55:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ixgbe_netbsd.c,v 1.11 2020/01/20 07:19:04 msaitoh Exp $ */ +/* $NetBSD: ixgbe_netbsd.c,v 1.12 2020/01/21 14:55:55 msaitoh Exp $ */ /* * Copyright (c) 2011 The NetBSD Foundation, Inc. * All rights reserved. @@ -225,10 +225,10 @@ ixgbe_jcl_destroy(struct adapter *adapte { ixgbe_extmem_head_t *eh = &rxr->jcl_head; - /* Free all dmamem */ - ixgbe_jcl_freeall(adapter, rxr); - if (eh->eh_initialized) { + /* Free all dmamem */ + ixgbe_jcl_freeall(adapter, rxr); + mutex_destroy(&eh->eh_mtx); eh->eh_initialized = false; } Index: src/sys/dev/pci/ixgbe/ixv.c diff -u src/sys/dev/pci/ixgbe/ixv.c:1.143 src/sys/dev/pci/ixgbe/ixv.c:1.144 --- src/sys/dev/pci/ixgbe/ixv.c:1.143 Tue Dec 17 05:49:01 2019 +++ src/sys/dev/pci/ixgbe/ixv.c Tue Jan 21 14:55:55 2020 @@ -1,4 +1,4 @@ -/*$NetBSD: ixv.c,v 1.143 2019/12/17 05:49:01 msaitoh Exp $*/ +/*$NetBSD: ixv.c,v 1.144 2020/01/21 14:55:55 msaitoh Exp $*/ /****************************************************************************** @@ -547,9 +547,7 @@ ixv_attach(device_t parent, device_t dev return; err_late: - ixgbe_free_transmit_structures(adapter); - ixgbe_free_receive_structures(adapter); - free(adapter->queues, M_DEVBUF); + ixgbe_free_queues(adapter); err_out: ixv_free_pci_resources(adapter); IXGBE_CORE_LOCK_DESTROY(adapter); @@ -674,13 +672,7 @@ ixv_detach(device_t dev, int flags) evcnt_detach(&hw->mbx.stats.reqs); evcnt_detach(&hw->mbx.stats.rsts); - ixgbe_free_transmit_structures(adapter); - ixgbe_free_receive_structures(adapter); - for (int i = 0; i < adapter->num_queues; i++) { - struct ix_queue *lque = &adapter->queues[i]; - mutex_destroy(&lque->dc_mtx); - } - free(adapter->queues, M_DEVBUF); + ixgbe_free_queues(adapter); IXGBE_CORE_LOCK_DESTROY(adapter);