From nobody Fri May 9 19:46:00 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZvKHY2lwsz5w4NN; Fri, 09 May 2025 19:46:01 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZvKHX5knYz4MD0; Fri, 09 May 2025 19:46:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746819960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=l5k97KaSJ4m6bLWF+fdSVza7IpG2jZnbCSM9SiWiGGw=; b=na2btAzAItkKLLbymnhBBWXlsJ1VMReWY3IU2TqF7IrJz4qTz7bb9HP3w8NhS03FkLG3cO YbyQWqhSNIiRvbsp8eORXZRVt1Bb0dPs7lz8WANK7TaJZn9cQHTNcLMzVA3Oo5EXUv2eF2 KqEWPtBdDkVZEJ6bgcnc/S0EhuZYJ7gzqhmPm2bLovoqBlPkBIISYCPpBg/Y1CE/2kLN2p Ff21vBwU9zcm8SMJDdjls33ieKk+zoOb1iteknLWZjzD5Wx+lEn/1wNfoW8PTh0TgDykyz czxB82MpqbP58fchBjIHr1efyu5m9CIGfjSEIsQOqbaZRMb3zGAURljPHY7zkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746819960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=l5k97KaSJ4m6bLWF+fdSVza7IpG2jZnbCSM9SiWiGGw=; b=acTL5LTZm/k4l6HYbX3tnZjbeku892jSrZ7O3AY9gHymfvTFk5qpyRuQKrkxUdrJyPnq8M K1cV0u9/3HAqSu0ycv1/Q+oI3NmAkis6Hwgod9IqP/HLtx82E9zBuW3j+Wqivr4gV9a1SV wsJGHDouzbK45mLcW80AbBdj3UebcNlZDIejVP+KHRQaTwb+Zmv2w2xTh8zctS+eth8hLj uAT0TBVPTWVJtnsrrl/Ybn1xjiHzMa/+nT2RqvM2lP98pnI9/F9Avi97jkLbKhPxG/IUci 7NnorWVywOtPN9dtzl6VDV8aEgoc6qyqgduYlh5/lPmaswD29WtKBmBs3Zv7dg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746819960; a=rsa-sha256; cv=none; b=KQYN1VfRGNtwXLVBVY1HYLhZpLceTMzN7tmUUwxfk9nSFp2XK97ZXPemcEhvF9JGHQ0S/d GI4MNsTMtKtuwDRZ5Ym5vUosLhtWDFacnFHHeDjrgvEYkl8Zjkz4rq1TBYuETUB68BG2Eb ON9S8IPUQ44Blj0h/3mAKUVe7+5bG/rGqjdJsDoFxv7ZEZyq+wuPU3EHVqr4FsPIYOsqNO qqgfvgGjL60rhxUt82gwEyUvAK8J3LlNUXedwwqw0S7SUvPjrDMOz6LG3MFBnpYF0kHt6Y WPZkDN9fn/X/IXyIVkKNJc9rgcDBlKeWp2ZUm5mkRSgsRXnVtfWr/hOrEhqWzg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4ZvKHX59gDz1Cbc; Fri, 09 May 2025 19:46:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 549Jk0q4081848; Fri, 9 May 2025 19:46:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 549Jk0AB081845; Fri, 9 May 2025 19:46:00 GMT (envelope-from git) Date: Fri, 9 May 2025 19:46:00 GMT Message-Id: <202505091946.549Jk0AB081845@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 2c65f965146a - main - LinuxKPI: pci: fix two errors in lkpi_pci_get_device() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c65f965146a7f822302715a439e17996d17453c Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=2c65f965146a7f822302715a439e17996d17453c commit 2c65f965146a7f822302715a439e17996d17453c Author: Bjoern A. Zeeb AuthorDate: 2025-05-04 20:02:07 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-05-09 19:45:10 +0000 LinuxKPI: pci: fix two errors in lkpi_pci_get_device() On any result we need to acquire a reference. pci_dev_get() deals with a NULL argument so we can simply pass what we "found" at the end. This will avoid reference count problems. If the iteration on the linux list in lkpi_pci_get_device() does not find a match pdev will still be defined at the end of the loop but not pointing to a valid pdev. Store the found entry in a 2nd variable which otherwise will be NULL. This will avoid random panics, usually in sysfs_remove_dir() when the reference gets released. Found during mt76 bringup. Sponsored by: The FreeBSD Foundation MFC after: 3 days Fixes: 8f61992d7cc11 Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D50153 --- sys/compat/linuxkpi/common/src/linux_pci.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 3651946c6ee5..5cf7c601d615 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -287,18 +287,22 @@ linux_pci_find(device_t dev, const struct pci_device_id **idp) struct pci_dev * lkpi_pci_get_device(uint16_t vendor, uint16_t device, struct pci_dev *odev) { - struct pci_dev *pdev; + struct pci_dev *pdev, *found; KASSERT(odev == NULL, ("%s: odev argument not yet supported\n", __func__)); + found = NULL; spin_lock(&pci_lock); list_for_each_entry(pdev, &pci_devices, links) { - if (pdev->vendor == vendor && pdev->device == device) + if (pdev->vendor == vendor && pdev->device == device) { + found = pdev; break; + } } + pci_dev_get(found); spin_unlock(&pci_lock); - return (pdev); + return (found); } static void