From nobody Thu Sep 4 02:09:49 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 4cHNGP4mqxz66Zv2; Thu, 04 Sep 2025 02:09:49 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cHNGP2wY9z3GFd; Thu, 04 Sep 2025 02:09:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756951789; 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=6Y/Dtpyi01ds29duAy/0XAHmw/C0v46kvDnuUKhb/7A=; b=rP7S1/sFE8n3NcWQlfWQz4RImq9FclHtjmn82Dai3xVe+hzYm191XGdhvd7VYbwV6CH/oe N0jpk8sKo720MsIHTwYGk0ALTlsZd02ZjmJnNugzsLtRbFVNV0h+9wpiUvc6l4/GzfnUh+ 4eq2sa5+dtm/QH6vWwGLeH8NkZc8vfqcwPCGPRTQE1lT74njcI4t928/EkWDbPk5VXyB0x uNllCWSXD8wBBp0jrfO4UMVmbTg717yqM5fRfCgo+wE+x/ShwEtJc/mlT18WE4wt2rXpdJ 7OEhC5hcusk1wP9ffRKqUAnZVpgZNArvnP0fQ/xx09OnR0TPH5grkYLCaj6Xlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1756951789; 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=6Y/Dtpyi01ds29duAy/0XAHmw/C0v46kvDnuUKhb/7A=; b=YaBrfloOpGg98hl+eg/VWg/k+/+dYZQh4zAvW3Ko9f3HQfKt2Cu3Ln2DUN026MMWUyNpIU qO73GXSkRaWmb86wyoC3lzCjvqZuFjrgmPqadtWHfscacscraSI9X0+d8Nquej7AY+OZhE vBv0O2C3keeUFA+wuZZgw7u8weYeKkNyOTz5qcdktMmpoxBiYRmSU8zRtKYXkU2GcBvLrF IGdkGaZrPMUxaJkv+t2ouWu6BDfWc9a04oPEj+4pMNoRm7l4Gp5HtDm5/jalwt+IkFwW/h kopSHaVDpUCJ/0aySPUkSlHkD/YMXkR8soZXckTGsxz30zoOwqBwz/DKrm5APg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1756951789; a=rsa-sha256; cv=none; b=Zn+4TX6jm8Kzli62Mx7b/TLlFVV7iEsk/H/dSlorNiMCwlUjFQHDwsBNKYGCDjmxtBS/Mm arnPrhs/oQavZkl8uJSUB3i74PMovg0s1350RLVk4u+vtKTN8NpX6VqKi0RWPF/5wV590m rlqHqTxR0T7rQx2BKzcUKlOSHGOmTd1EYd7RBtXZNFyWYqBVkdzL2qp+D/5q/aOZZ+rb+u aOeP2b62NdqmE6eNdt7oKTjRITIrv4qWpA7CffFmFj/cL7RdV34k1INw1i4GkMCsLPlEGt TONCAJi5y3+4azzWdCp7rHGfi26VS+r+vgHHv3h/dFmcREecz259QGTPmO13kw== 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 4cHNGP1QQtzjbs; Thu, 04 Sep 2025 02:09:49 +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 58429nnx012290; Thu, 4 Sep 2025 02:09:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58429nGs012287; Thu, 4 Sep 2025 02:09:49 GMT (envelope-from git) Date: Thu, 4 Sep 2025 02:09:49 GMT Message-Id: <202509040209.58429nGs012287@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: cc70c7989bfb - main - linsysfs: error check device-directory creation 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cc70c7989bfbc528806a3abce2194f739089286b Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=cc70c7989bfbc528806a3abce2194f739089286b commit cc70c7989bfbc528806a3abce2194f739089286b Author: Kyle Evans AuthorDate: 2025-09-04 02:08:51 +0000 Commit: Kyle Evans CommitDate: 2025-09-04 02:08:51 +0000 linsysfs: error check device-directory creation This one in particular is ripe with opportunities to trigger a duplicate node error in pfs_create_dir(), so we do actually want to error-check it. The rest, more or less, should be expected not to fail. We'll propagate the error from pfs_create_dir() up through linsysfs_run_bus and complain about the device node that caused the error. Note that we avoid failing vfs_init() since a partially-constructed linsysfs with missing devices is probably more useful than missing linsysfs entirely. While we're here, convert two malloc() that weren't being error checked to M_WAITOK -- we already wait in the rest of the function, might as well do the same here. Add a missing newline to the pseudofs error mesage. Reviewed by: fuz, kib Differential Revision: https://reviews.freebsd.org/D52038 --- sys/compat/linsysfs/linsysfs.c | 46 +++++++++++++++++++++++++++++++++--------- sys/fs/pseudofs/pseudofs.c | 2 +- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/sys/compat/linsysfs/linsysfs.c b/sys/compat/linsysfs/linsysfs.c index 7f70221b420d..b70cb43d0f9a 100644 --- a/sys/compat/linsysfs/linsysfs.c +++ b/sys/compat/linsysfs/linsysfs.c @@ -267,6 +267,8 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, struct pci_devinfo *dinfo; char *device, *host, *new_path, *devname; + children = NULL; + device = host = NULL; new_path = path; devname = malloc(16, M_TEMP, M_WAITOK); @@ -294,6 +296,10 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, strcat(new_path, device); dir = pfs_create_dir(dir, device, NULL, NULL, NULL, 0); + if (dir == NULL) { + error = EEXIST; + goto out; + } cur_file = pfs_create_file(dir, "vendor", &linsysfs_fill_vendor, NULL, NULL, NULL, PFS_RD); @@ -338,10 +344,10 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, NULL, NULL, NULL, 0); scsi_host = malloc(sizeof( struct scsi_host_queue), - M_DEVBUF, M_NOWAIT); + M_DEVBUF, M_WAITOK); scsi_host->path = malloc( strlen(new_path) + 1, - M_DEVBUF, M_NOWAIT); + M_DEVBUF, M_WAITOK); scsi_host->path[0] = '\000'; bcopy(new_path, scsi_host->path, strlen(new_path) + 1); @@ -360,8 +366,6 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, TAILQ_INSERT_TAIL(&scsi_host_q, scsi_host, scsi_host_next); } - free(device, M_TEMP); - free(host, M_TEMP); } } @@ -401,17 +405,37 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, error = device_get_children(dev, &children, &nchildren); if (error == 0) { - for (i = 0; i < nchildren; i++) - if (children[i]) - linsysfs_run_bus(children[i], dir, scsi, + for (i = 0; i < nchildren; i++) { + if (children[i]) { + error = linsysfs_run_bus(children[i], dir, scsi, chardev, drm, new_path, prefix); - free(children, M_TEMP); + if (error != 0) { + printf( + "linsysfs_run_bus: %s omitted from sysfs tree, error %d\n", + device_get_nameunit(children[i]), + error); + } + } + } + + /* + * We override the error to avoid cascading failures; the + * innermost device that failed in a tree is probably the most + * significant one for diagnostics, its parents would be noise. + */ + error = 0; } + +out: + free(host, M_TEMP); + free(device, M_TEMP); + if (children != NULL) + free(children, M_TEMP); if (new_path != path) free(new_path, M_TEMP); free(devname, M_TEMP); - return (1); + return (error); } /* @@ -509,6 +533,10 @@ linsysfs_init(PFS_INIT_ARGS) return (0); } + /* + * This assumes that the root node is unlikely to error out in + * linsysfs_run_bus, which may or may not be true. + */ dev = devclass_get_device(devclass, 0); linsysfs_run_bus(dev, pci, scsi, chardev, drm, "/pci0000:00", "0000"); diff --git a/sys/fs/pseudofs/pseudofs.c b/sys/fs/pseudofs/pseudofs.c index ef45f96a6192..cc34489b92f2 100644 --- a/sys/fs/pseudofs/pseudofs.c +++ b/sys/fs/pseudofs/pseudofs.c @@ -133,7 +133,7 @@ pfs_add_node(struct pfs_node *parent, struct pfs_node *pn) for (iter = parent->pn_nodes; iter != NULL; iter = iter->pn_next) { if (strcmp(pn->pn_name, iter->pn_name) != 0) continue; - printf("pfs_add_node: homonymous siblings: '%s/%s' type %d", + printf("pfs_add_node: homonymous siblings: '%s/%s' type %d\n", parent->pn_name, pn->pn_name, pn->pn_type); /* Do not detach, because we are not yet attached. */ pn->pn_parent = NULL;