From nobody Fri May 09 19:45:59 2025 X-Original-To: dev-commits-src-all@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 4ZvKHW6HyQz5w42H; Fri, 09 May 2025 19:45:59 +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 4ZvKHW5dGrz4Lrr; Fri, 09 May 2025 19:45:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746819959; 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=mRs5YZmD593uH7EalMBUC4eiWmSyZoydgv8x7mU2zdU=; b=xOR8a4cUssRAFu6atrdTn9IbzeGwh3ZfrYfDg6v84NJ8TEw4Y7pN1yYewgk8+0IX1CKYg+ sDPfFIg5ILueAnzf7P057b0u0z3wtnAkqGggavO1zYmRBJKK73dJk0+69jq/dHglSGbwwM GvByaAYexfpSmFuGhfdVvhkfQiVhvFwOfqUhrPpoP1SbimcnGU9XpIxuCHO58l06y1rUn5 s5dC13Q9HI+HjdD5FHZg5WPgJpS27qaPmwlekQKHeh0OQBRRKVNmQYmOXn3ydWG6XnzUCF q4dVtLNPBhB7g4fID5YsqnVp8DbxQk9uy6D4i9QcbdIb3OP/ZIOJBuP0p+50rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746819959; 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=mRs5YZmD593uH7EalMBUC4eiWmSyZoydgv8x7mU2zdU=; b=tHkD+iIeJayetGBUos/3DocRJ+yXZoY2v32mrAxBzaK12kfRsFs4Y7vqbxlKEI9ZETEe2B cRoMpp7Wwrbv4eYkrioDtPsN/Egz4SeNx4L1eKgxGe7bhEb0iSFqohpAO7P9ywVS2ZzvzH OIF1oTMP9QQIGRB29syg4DfgLuqCfbnAp5EWhZPdZWpANfF9VL5hKHiMBouRt2FniHE8gd QtuVn4tjKFJr9ziLg/xIbmqSFpiHkUcTbrLzgemDPdHmxEuSFA9q/iIwh45dxsR/ZXJL7d x+DsM8h/NT2KOw2lnwKJmtkhjQpd/hfj7buHe8hf5Q1TF8AjXxjKJ1HL6yz/CQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746819959; a=rsa-sha256; cv=none; b=MjYeaakgANqPBqjWF1RqYfWLH2NHqxtGRqMLTpdKDuPCmfYpuQs+30vV4HMc6Ke06W1QnF e5KtGspCTZnZbymmGv2c2tDNQoYPmwUwPOToOLhPJIZlNszVVnksSpeARpJGPQWYBvs0NG lTDAgTTRucuWHoh+ebQMuHPzCYEpWaocR8DFadmCPCY2FPXb7aehFpGVbDr+gLkOix4LQA xRPOvgL9whEx3NKrGfHJIjPOCWhjfDFnUCxvGMcGYRblaEt/qj9uvKYhv1ot2Wch6uhD4v ls5FMolNgY/0/Tgz/UB9FKc7lwQTTkmoCg+fWImadvwaAcuFOzm60dJgGGt5CQ== 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 4ZvKHW4r6Nz81; Fri, 09 May 2025 19:45:59 +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 549Jjxkc081805; Fri, 9 May 2025 19:45:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 549Jjx0x081802; Fri, 9 May 2025 19:45:59 GMT (envelope-from git) Date: Fri, 9 May 2025 19:45:59 GMT Message-Id: <202505091945.549Jjx0x081802@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: 96e86aa6faa6 - main - LinuxKPI: pci: deal with kobject_add() being able to fail List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 96e86aa6faa6fde4ff75fd757db55afe9e4be132 Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=96e86aa6faa6fde4ff75fd757db55afe9e4be132 commit 96e86aa6faa6fde4ff75fd757db55afe9e4be132 Author: Bjoern A. Zeeb AuthorDate: 2025-05-04 19:58:15 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-05-09 19:45:09 +0000 LinuxKPI: pci: deal with kobject_add() being able to fail lkpifill_pci_dev() uses a sequene of kobject_init/set_name/add. The problem is that kobject_add could fail. Move the entire logic to the beginning of the function, switch to kobject_init_and_add() and check the return code. Make lkpifill_pci_dev() return the error and deal in the callers with a possible error accordingly. Sponsored by: The FreeBSD Foundation MFC after: 3 days Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D50154 --- sys/compat/linuxkpi/common/src/linux_pci.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index fa5e3c71fad0..3651946c6ee5 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -309,9 +309,18 @@ lkpi_pci_dev_release(struct device *dev) spin_lock_destroy(&dev->devres_lock); } -static void +static int lkpifill_pci_dev(device_t dev, struct pci_dev *pdev) { + int error; + + error = kobject_init_and_add(&pdev->dev.kobj, &linux_dev_ktype, + &linux_root_device.kobj, device_get_nameunit(dev)); + if (error != 0) { + printf("%s:%d: kobject_init_and_add returned %d\n", + __func__, __LINE__, error); + return (error); + } pdev->devfn = PCI_DEVFN(pci_get_slot(dev), pci_get_function(dev)); pdev->vendor = pci_get_vendor(dev); @@ -341,12 +350,10 @@ lkpifill_pci_dev(device_t dev, struct pci_dev *pdev) pdev->msi_desc = malloc(pci_msi_count(dev) * sizeof(*pdev->msi_desc), M_DEVBUF, M_WAITOK | M_ZERO); - kobject_init(&pdev->dev.kobj, &linux_dev_ktype); - kobject_set_name(&pdev->dev.kobj, device_get_nameunit(dev)); - kobject_add(&pdev->dev.kobj, &linux_root_device.kobj, - kobject_name(&pdev->dev.kobj)); spin_lock_init(&pdev->dev.devres_lock); INIT_LIST_HEAD(&pdev->dev.devres_head); + + return (0); } static void @@ -374,9 +381,14 @@ struct pci_dev * lkpinew_pci_dev(device_t dev) { struct pci_dev *pdev; + int error; pdev = malloc(sizeof(*pdev), M_DEVBUF, M_WAITOK|M_ZERO); - lkpifill_pci_dev(dev, pdev); + error = lkpifill_pci_dev(dev, pdev); + if (error != 0) { + free(pdev, M_DEVBUF); + return (NULL); + } pdev->dev.release = lkpinew_pci_dev_release; return (pdev); @@ -525,7 +537,10 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, device_set_ivars(dev, dinfo); } - lkpifill_pci_dev(dev, pdev); + error = lkpifill_pci_dev(dev, pdev); + if (error != 0) + return (error); + if (isdrm) PCI_GET_ID(device_get_parent(parent), parent, PCI_ID_RID, &rid); else