From nobody Thu May 15 09:52: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 4ZylrW3yWFz5w3s8; Thu, 15 May 2025 09:52: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 4ZylrW36T4z3C0H; Thu, 15 May 2025 09:52:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747302779; 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=TrnDH0YpN/1aJv7r+fZAsQ1V9dI/izQ/z5IZpLVxdjg=; b=VzvgHROmDOYFt+7VfTkfEZXnhkNl9bqKcI65g93G2hG0acZjvU1gMf0LGID5RVJLDel7A1 v7vw6B5QJLTZMZPfYjNBTxt2ARgUeVtZjERtwTFrQKeRbhIE0Uo2XzHlGTy28A53cePmlT egXQoUa6HBquFRmGqDt/a9ariDB2hnabBjnJ7CkN/hs7nUsonvev1Jvyu/lYeyV/9PokPf PN6xMhgp+JmHAnUrGrg+8fgagdJTbfHkU+yUZ0oTU6pu0WPxdbUpLP2himtuXEs2OMhJx5 wKS5GxrHYZgyg9MN+XIzBPUlIJnPqKw6h/0g7faA/KrEYyFbtWMUIQbruso91g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747302779; 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=TrnDH0YpN/1aJv7r+fZAsQ1V9dI/izQ/z5IZpLVxdjg=; b=gNHvKFwMc8JQSj0A66SX8cXHjrNxwJlG/QkXb8pFv/lg6v7vki6w8uvsWGTcb3CGaZQ1gG 69TjtPpFXSxxZvNNfDylito8XvupO9cHEAoHS92zEl+ldmwM0OyOIbJHorQU+IgjwPOWHi kyIukd1uSCQWK6pnkATnwWjnIUgGGPRBWxndVrYh04aNa0iQzgbnlYYjVJsMmyvo9qhS5R e1XrZwpjhx7cR1C0pUr3v5aOZXwsL8VGOGInu7pHqC7rWsV7PpqRj9OwehMYqKx+QRjUGl qNSSqvkGyY3FPvJqVjgFNJ4cKoE8ZiDWq+twoRt3cffds2BqSk5YS5LRaMEMLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747302779; a=rsa-sha256; cv=none; b=C8+C3wHuVBYBffZzZlfJAEXuHDimzFVRjhln95iaaZaioHiUGUO17qdiqh8svt2UFbaA4F RVK9ozfnmPdZynWgjQwvjiUx42pBGM4/Yg05uVk1e2XhoXUfWu8z+o2JyuNVhYMtWvX4BC 9wzKegQYWSWUiQcNTJ4JbY9n0P/duuwaoHYZil8ICuFgJK/lajgi3pdblEnNxobWTOIyVQ Kn/hm68UWKueqbnNeRoA3J/KzAqZ4GbJmDyU732KjW1hLxW3/OFJxdjHhihMCh76HNAGGU 6Wm71Dp7q80udjyk+S/hH1rSCJfr5L8iZ7LfwwiWfq/IIxirr+0iESYzshN3QA== 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 4ZylrW2jXvz1BV6; Thu, 15 May 2025 09:52: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 54F9qxIb050740; Thu, 15 May 2025 09:52:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54F9qxlJ050737; Thu, 15 May 2025 09:52:59 GMT (envelope-from git) Date: Thu, 15 May 2025 09:52:59 GMT Message-Id: <202505150952.54F9qxlJ050737@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: 96ee4e56125d - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 96ee4e56125de12280457c153f82868a7f2751e7 Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=96ee4e56125de12280457c153f82868a7f2751e7 commit 96ee4e56125de12280457c153f82868a7f2751e7 Author: Bjoern A. Zeeb AuthorDate: 2025-05-04 19:58:15 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-05-15 09:50:55 +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 Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D50154 (cherry picked from commit 96e86aa6faa6fde4ff75fd757db55afe9e4be132) --- 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 36dbac24496b..bee79f0478c8 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -310,9 +310,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); @@ -342,12 +351,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 @@ -375,9 +382,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); @@ -508,7 +520,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