From nobody Thu May 15 09:53:00 2025 X-Original-To: dev-commits-src-branches@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 4ZylrY2f9gz5w3tw; Thu, 15 May 2025 09:53: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 4ZylrX51dsz3C0R; Thu, 15 May 2025 09:53:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747302780; 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=gmjszkNPYDm6TYNXCoDcu3oZw75P1+wH9mtTEQOEerQ=; b=PRhnaKzbyzDE1zapbeMMV6F+T9EQrqsciXZ7fkF4EetTxg1E7BzPR0XS6JXxYIyZ0GceB6 FfwJcCRJGKxfvYiStgVI3yHa7S1t0SM3zK3XbHlx4jDiSfOslRKEyxVZqWf53h+d1KzEH/ qz8PHAECkgwKmrL/5+FEl2SZtUKZIumrF6SDLRQHnYdy07X1l98m43CFNpeezjALLI/dTx 312+dCJDCNrgD1Mz9+R6n8GIKh7U07cIm5O1/aLPq5v07s/7ybsMXwpo24cRwfA2letTQL 5GqRic6pPgdxYuO42Vd2MCBfZd1YyRBrQlAPiEa8CMbUgjrAxig78enp60ieTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747302780; 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=gmjszkNPYDm6TYNXCoDcu3oZw75P1+wH9mtTEQOEerQ=; b=E0lHpqqNsD99mAupOvOOPVWQGbx0A+pW0HuzfHoB9/vYKjoisFwMG2k4JDaNcLKKAGYID7 IJD0fFG32uTRkCZuBWnORL6zlfYsZWMlH115WeK+IfqCeWQ2VeyorAqEBtdfycjJAH72yO pKr3mG3raTLF+44BzSq/+L6bfcsUrsb8IPh6QgHVSCRdukSIQj5uoijQSzeO6f37teaA9v 3vcdKgrcDPGF2BFrJERddIxYsIx55R62XxMgs/YNFUq7PW+zDgFepZhpo1o0G/GtlYNkuJ lACM9PsuHDlzg0NtLwU3UUCq+HQzfauxJXFTFuKJnAB7vL2sl2bEDxD7AeyN9Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747302780; a=rsa-sha256; cv=none; b=eRW0vyKWvnGCeEWF5GslmBTsiaHQRD+NZgP+vWQXqDlkW1VZbaY/iWY4GTbYtjr5rNSIZu AIhN+Xka+ailKT9LaWe9zi3HB/ZaA/bTT9ZFB40dzB9DMISJc24s7UZbXZTMwb6yyERgFc d1OOmXNd0iR8FdxMfxUJjX2RB77XFEBb0O6OZnrGR4QNmf6FXBuJJPfMUQJumuZxNUzrzE 0Z0Kdzl2igHX/X0L9onD6iSOnAOHZMFuwIMIR71I8gNYzUPrcb5NQossodkzZxaWxX2tcy oYtNyTthTF5Z3/8e1tX1WHAqelF77vIDdx/9g28Ap/3w4shDXyEedbfJI/mO3w== 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 4ZylrX3fQVz1BHm; Thu, 15 May 2025 09:53: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 54F9r0Hm050783; Thu, 15 May 2025 09:53:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54F9r0j6050780; Thu, 15 May 2025 09:53:00 GMT (envelope-from git) Date: Thu, 15 May 2025 09:53:00 GMT Message-Id: <202505150953.54F9r0j6050780@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: c6c953fc43d8 - stable/14 - LinuxKPI: pci: fix two errors in lkpi_pci_get_device() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: c6c953fc43d86417bbf18a41a328c60f02a34c69 Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=c6c953fc43d86417bbf18a41a328c60f02a34c69 commit c6c953fc43d86417bbf18a41a328c60f02a34c69 Author: Bjoern A. Zeeb AuthorDate: 2025-05-04 20:02:07 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-05-15 09:50:55 +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 Fixes: 8f61992d7cc11 Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D50153 (cherry picked from commit 2c65f965146a7f822302715a439e17996d17453c) --- 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 bee79f0478c8..2c2f92082a4e 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -288,18 +288,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