From owner-dev-commits-src-all@freebsd.org Sat Apr 24 03:31:42 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D83EB5EF76E; Sat, 24 Apr 2021 03:31:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FRxXZ5rNbz4RpG; Sat, 24 Apr 2021 03:31:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id BB4A1199C8; Sat, 24 Apr 2021 03:31:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13O3VgII016428; Sat, 24 Apr 2021 03:31:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13O3VgLZ016427; Sat, 24 Apr 2021 03:31:42 GMT (envelope-from git) Date: Sat, 24 Apr 2021 03:31:42 GMT Message-Id: <202104240331.13O3VgLZ016427@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Tai-hwa Liang Subject: git: 2acbe67787d2 - main - sound(4): fixing panic for INVARIANTS kernel MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avatar X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2acbe67787d2ba08b62713ccc3abcef01e7ced09 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Apr 2021 03:31:42 -0000 The branch main has been updated by avatar: URL: https://cgit.FreeBSD.org/src/commit/?id=2acbe67787d2ba08b62713ccc3abcef01e7ced09 commit 2acbe67787d2ba08b62713ccc3abcef01e7ced09 Author: Tai-hwa Liang AuthorDate: 2021-04-22 12:45:18 +0000 Commit: Tai-hwa Liang CommitDate: 2021-04-24 03:27:43 +0000 sound(4): fixing panic for INVARIANTS kernel 3e7bae08210e0 turns the BUS_READ_IVAR() failure from a warning into a KASSERT. For certain PCI audio devices such like snd_csa(4) and snd_emu10kx(4), the ac97_create() keeps the device handler generated by device_add_child(pci_dev, "pcm"), which is not really a PCI device handler. This in turn causes the subsequent pci_get_subdevice() inside ac97_initmixer() triggering a panic. This patch tries to put a bandaid for the aforementioned pcm device children such that they can use the correct PCI handler(from parent) to avoid a KASSERT panic in the INVARIANTS kernel. Tested with: snd_csa(4), snd_ich(4), snd_emu10kx(4) Reviewed by: imp MFC after: 1 month --- sys/dev/sound/pcm/ac97.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/dev/sound/pcm/ac97.c b/sys/dev/sound/pcm/ac97.c index 960176329b3e..3dc614083660 100644 --- a/sys/dev/sound/pcm/ac97.c +++ b/sys/dev/sound/pcm/ac97.c @@ -602,6 +602,7 @@ ac97_initmixer(struct ac97_info *codec) ac97_patch codec_patch; const char *cname, *vname; char desc[80]; + device_t pdev; u_int8_t model, step; unsigned i, j, k, bit, old; u_int32_t id; @@ -641,9 +642,14 @@ ac97_initmixer(struct ac97_info *codec) return ENODEV; } + pdev = codec->dev; + while (strcmp(device_get_name(device_get_parent(pdev)), "pci") != 0) { + /* find the top-level PCI device handler */ + pdev = device_get_parent(pdev); + } codec->id = id; - codec->subvendor = (u_int32_t)pci_get_subdevice(codec->dev) << 16; - codec->subvendor |= (u_int32_t)pci_get_subvendor(codec->dev) & + codec->subvendor = (u_int32_t)pci_get_subdevice(pdev) << 16; + codec->subvendor |= (u_int32_t)pci_get_subvendor(pdev) & 0x0000ffff; codec->noext = 0; codec_patch = NULL;