From nobody Tue Jan 4 17:18:20 2022 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 D195519353B9; Tue, 4 Jan 2022 17:18:22 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JSzpj4nhDz4gnJ; Tue, 4 Jan 2022 17:18:21 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 56E1D1CE8D; Tue, 4 Jan 2022 17:18:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 204HIKGb057999; Tue, 4 Jan 2022 17:18:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 204HIK5i057998; Tue, 4 Jan 2022 17:18:20 GMT (envelope-from git) Date: Tue, 4 Jan 2022 17:18:20 GMT Message-Id: <202201041718.204HIK5i057998@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: d97bfe3ff840 - stable/13 - bus: Cleanup device_probe_child() 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d97bfe3ff8404e04dada9d7b86d8379d4713c2e8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641316701; 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=9UUCkazXRDqDkZ9VnIaOUKRbI380UlefQrDbgmFUbXM=; b=CCk01gmYHpDKkIIUDKuzWI++vdLRniW5BA0CnR5af18kTcK5QTpT8J9/fTDNUFAlhIGyfE tIsJ8W8bwguMjh7Qbtaz6b7Zj2mQmYMdD2Pgk7hHYcUi+8UttczT1roqqu4xCbcugn4eUJ Aub4uPINAoezFhfsDO1Fj1veWlq4jwQtRgbjSv2Eju20j4LwNDNGQcDwJcmQEU/FtU5KQn Sq4rHUihH2xITGE8y7IezeNjFMynHg14EVw38SDQsHz28/Lx8T3VKDP4ZeOM+X2ME4Z+06 gaiyqGElal4s7DhqCnyYN5Rx2xWa6HKyBu3bKW0aMQIMJv0QZ4tSkCnRSSCqkQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641316701; a=rsa-sha256; cv=none; b=tNAsoxja868yg3W8uER8Ij2So/PJhtZk54ya1G3JDefMVHtPpkj2rQ8/v4dAczVctrYgeK A9dNmngIrZcn5gde9LQ/4Cvr4yojXJ3ZjAFmtsiJppzviDCKu3tU6km4YQlFm7+96tTW9B 4M2xwoZAzK5tiwmEd+rE8rBujYDGNEevGoeWgYV9Cd5tZXUD47P5s3MJEEj5DdQ9oGTBoR mgSYKqOogHCWjbTwp6uua8B3H9MmnNgWbxCwn+i32Re2LCUm2TGHXC1+yLaWr3uwk847gE 1DUdgSZfKGrivbPP7kHzGBs7eP5OZq9E3aJkAin1rm0Xfo04Zvu5q+NJOIdF5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=d97bfe3ff8404e04dada9d7b86d8379d4713c2e8 commit d97bfe3ff8404e04dada9d7b86d8379d4713c2e8 Author: Alexander Motin AuthorDate: 2021-09-25 00:27:10 +0000 Commit: Alexander Motin CommitDate: 2022-01-04 17:10:55 +0000 bus: Cleanup device_probe_child() When device driver probe method returns 0, i.e. absolute priority, do not remove its class from the device just to set it back few lines later, that may change the device unit number, etc. and after which we'd better call the probe again. If during search we found some driver with absolute priority, we do not need to set device driver and class since we haven't removed them before. It should not happen, but if second probe method call failed, remove the driver and possibly the class from the device as it was when we started. Reviewed by: imp, jhb Differential Revision: https://reviews.freebsd.org/D32125 (cherry picked from commit f73c2bbf811ba77b2fe91b5bc0cbe19e9f7eb6c4) --- sys/kern/subr_bus.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index a7c09f6e9374..185a39cdb0ef 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -2076,6 +2076,7 @@ device_probe_child(device_t dev, device_t child) driverlink_t best = NULL; driverlink_t dl; int result, pri = 0; + /* We should preserve the devclass (or lack of) set by the bus. */ int hasclass = (child->devclass != NULL); GIANT_REQUIRED; @@ -2127,11 +2128,6 @@ device_probe_child(device_t dev, device_t child) result = DEVICE_PROBE(child); - /* Reset flags and devclass before the next probe. */ - child->devflags = 0; - if (!hasclass) - (void)device_set_devclass(child, NULL); - /* * If the driver returns SUCCESS, there can be * no higher match for this device. @@ -2142,6 +2138,11 @@ device_probe_child(device_t dev, device_t child) break; } + /* Reset flags and devclass before the next probe. */ + child->devflags = 0; + if (!hasclass) + (void)device_set_devclass(child, NULL); + /* * Reset DF_QUIET in case this driver doesn't * end up as the best driver. @@ -2186,36 +2187,43 @@ device_probe_child(device_t dev, device_t child) break; } + if (best == NULL) + return (ENXIO); + /* * If we found a driver, change state and initialise the devclass. */ - if (best) { + if (pri < 0) { /* Set the winning driver, devclass, and flags. */ + result = device_set_driver(child, best->driver); + if (result != 0) + return (result); if (!child->devclass) { result = device_set_devclass(child, best->driver->name); - if (result != 0) + if (result != 0) { + (void)device_set_driver(child, NULL); return (result); + } } - result = device_set_driver(child, best->driver); - if (result != 0) - return (result); resource_int_value(best->driver->name, child->unit, "flags", &child->devflags); - if (pri < 0) { - /* - * A bit bogus. Call the probe method again to make - * sure that we have the right description. - */ - DEVICE_PROBE(child); + /* + * A bit bogus. Call the probe method again to make sure + * that we have the right description. + */ + result = DEVICE_PROBE(child); + if (result > 0) { + if (!hasclass) + (void)device_set_devclass(child, NULL); + (void)device_set_driver(child, NULL); + return (result); } - child->state = DS_ALIVE; - - bus_data_generation_update(); - return (0); } - return (ENXIO); + child->state = DS_ALIVE; + bus_data_generation_update(); + return (0); } /**