Date: Thu, 15 May 2025 09:52:59 GMT From: "Bjoern A. Zeeb" <bz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 96ee4e56125d - stable/14 - LinuxKPI: pci: deal with kobject_add() being able to fail Message-ID: <202505150952.54F9qxlJ050737@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=96ee4e56125de12280457c153f82868a7f2751e7 commit 96ee4e56125de12280457c153f82868a7f2751e7 Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2025-05-04 19:58:15 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505150952.54F9qxlJ050737>