From owner-svn-src-all@freebsd.org Sat May 14 06:07:16 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B2A4CB3A7AE; Sat, 14 May 2016 06:07:16 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 82A6F1D1B; Sat, 14 May 2016 06:07:16 +0000 (UTC) (envelope-from kp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4E67F20067101; Sat, 14 May 2016 06:07:15 GMT (envelope-from kp@FreeBSD.org) Received: (from kp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4E67F1u067100; Sat, 14 May 2016 06:07:15 GMT (envelope-from kp@FreeBSD.org) Message-Id: <201605140607.u4E67F1u067100@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kp set sender to kp@FreeBSD.org using -f From: Kristof Provost Date: Sat, 14 May 2016 06:07:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299725 - head/sys/dev/virtio/network X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 May 2016 06:07:16 -0000 Author: kp Date: Sat May 14 06:07:15 2016 New Revision: 299725 URL: https://svnweb.freebsd.org/changeset/base/299725 Log: vtnet: fix panic on unload Since r276367 added the virtio_mmio support vtnet_modevent() gets called twice. This resulted in a memory leak during load and a panic on unload. Count the loads so we only initialise once (just like cxgbe(4)), and only clean up in the final unload. PR: 209428 Submitted by: novel@FreeBSD.org MFC after: 1 week Modified: head/sys/dev/virtio/network/if_vtnet.c Modified: head/sys/dev/virtio/network/if_vtnet.c ============================================================================== --- head/sys/dev/virtio/network/if_vtnet.c Sat May 14 06:06:48 2016 (r299724) +++ head/sys/dev/virtio/network/if_vtnet.c Sat May 14 06:07:15 2016 (r299725) @@ -311,21 +311,22 @@ MODULE_DEPEND(vtnet, netmap, 1, 1, 1); static int vtnet_modevent(module_t mod, int type, void *unused) { - int error; - - error = 0; + int error = 0; + static int loaded = 0; switch (type) { case MOD_LOAD: - vtnet_tx_header_zone = uma_zcreate("vtnet_tx_hdr", - sizeof(struct vtnet_tx_header), - NULL, NULL, NULL, NULL, 0, 0); + if (loaded++ == 0) + vtnet_tx_header_zone = uma_zcreate("vtnet_tx_hdr", + sizeof(struct vtnet_tx_header), + NULL, NULL, NULL, NULL, 0, 0); break; case MOD_QUIESCE: - case MOD_UNLOAD: if (uma_zone_get_cur(vtnet_tx_header_zone) > 0) error = EBUSY; - else if (type == MOD_UNLOAD) { + break; + case MOD_UNLOAD: + if (--loaded == 0) { uma_zdestroy(vtnet_tx_header_zone); vtnet_tx_header_zone = NULL; }