Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1179038rdh; Fri, 24 Nov 2023 06:54:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+nvHGN9zynFolusTscIKUfAOXDuBQ9qTLE4quAuOZy5mmOVfXaGls8Pqy8n2+WhP0+00y X-Received: by 2002:a17:90b:1d11:b0:27c:fc2a:a178 with SMTP id on17-20020a17090b1d1100b0027cfc2aa178mr3676599pjb.9.1700837661597; Fri, 24 Nov 2023 06:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700837661; cv=none; d=google.com; s=arc-20160816; b=ab/1TasM0EFFraA7F+rbvkFpVtKgbd9Qerd90HZzcErFbYrh/xroahRUMsit0OVcd+ I6ziVD1pMN1bUAa0JUHvVnw19+OtcM/KmXTFA5EJyu7nYQUfkz3LW5T+k370jdeusetm D7tu/yp16EU9H5nfYU7fn/yfm/VrNi4ypocle6++HYyfAPyo0Ht/1Rn/VcpX0t34aJoC xiDgQNUnSRpS2Hnk3o8Qpe840T+Y6UTJJi/vLVyZ3aKmEcUiKZX5a7Y8GWRb4xFdSKgl wx2m43fuwS9CbCXCY8bJMxGRxXZyd/LpvtCQAglqg5QPhbOXEguwojycs1c37wDj/sic fh6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9d8Krv75NYTcMsc0Jn3SXxLgWWnAu0XPujwp1OVwYo8=; fh=ocxZ/h3ioldfpEoEIh3pDUh60EAto7Ia5QGaG5MGfZA=; b=X0/xcDH/JD9HPJIPHcVcgRHQVqXR14PsvYZdfYrW6F3FHfhjI7d0JQYCgiroiou3Wf f2wGPrFWhZcW4zPkwKY8zf1KyMR9mH6t8m50zpNpY8HL40Ht3ujdIHmmnksoHncw9xc+ fcKs8RUSPiac0E8DsrY5SHkZsFYECqLhA9znhEpJktfvP4ilE8TnmLBwajeXsgqx+QRN RDECzCOeaD3afLIKpuxAw3BR7txqnCEa49QKmryFEldEsx04GF//sBzGHfiiDrqHRRsP NZIQRA5oqsTcpPKPEUlCPR/5xSj+P76REWUZtQmw7/IdRSRJaDaCKokrp0+kmnnTwvS0 MknQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id o14-20020a17090a4b4e00b0027cf6bb27dfsi4138064pjl.39.2023.11.24.06.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 06:54:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3C7C38335702; Fri, 24 Nov 2023 06:54:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345486AbjKXOxr (ORCPT + 99 others); Fri, 24 Nov 2023 09:53:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbjKXOxl (ORCPT ); Fri, 24 Nov 2023 09:53:41 -0500 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97F5A19A2 for ; Fri, 24 Nov 2023 06:53:47 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r6XYp-0006o6-QO; Fri, 24 Nov 2023 15:53:39 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r6XYp-00BI0w-3G; Fri, 24 Nov 2023 15:53:39 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1r6XYo-00D3lZ-35; Fri, 24 Nov 2023 15:53:38 +0100 From: Oleksij Rempel To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Ulf Hansson , Mark Brown Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-pm@vger.kernel.org, =?UTF-8?q?S=C3=B8ren=20Andersen?= Subject: [PATCH v1 1/3] driver core: move core part of device_shutdown() to a separate function Date: Fri, 24 Nov 2023 15:53:36 +0100 Message-Id: <20231124145338.3112416-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231124145338.3112416-1-o.rempel@pengutronix.de> References: <20231124145338.3112416-1-o.rempel@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 24 Nov 2023 06:54:19 -0800 (PST) Split the device_shutdown() as a preparation for the prioritization support. Signed-off-by: Oleksij Rempel --- drivers/base/core.c | 110 +++++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 47 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 67ba592afc77..0f5646a097d3 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -4719,12 +4719,73 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid) } EXPORT_SYMBOL_GPL(device_change_owner); +/** + * device_shutdown_one - shut down a device + * @dev: device to shut down + * + * It is called with the device lock held. + * + * The device must be on the devices_kset list. + */ +static void device_shutdown_one_locked(struct device *dev) +{ + struct device *parent; + + lockdep_assert_held(&devices_kset->list_lock); + /* + * hold reference count of device's parent to + * prevent it from being freed because parent's + * lock is to be held + */ + parent = get_device(dev->parent); + get_device(dev); + /* + * Make sure the device is off the kset list, in the + * event that dev->*->shutdown() doesn't remove it. + */ + list_del_init(&dev->kobj.entry); + spin_unlock(&devices_kset->list_lock); + + /* hold lock to avoid race with probe/release */ + if (parent) + device_lock(parent); + device_lock(dev); + + /* Don't allow any more runtime suspends */ + pm_runtime_get_noresume(dev); + pm_runtime_barrier(dev); + + if (dev->class && dev->class->shutdown_pre) { + if (initcall_debug) + dev_info(dev, "shutdown_pre\n"); + dev->class->shutdown_pre(dev); + } + if (dev->bus && dev->bus->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->bus->shutdown(dev); + } else if (dev->driver && dev->driver->shutdown) { + if (initcall_debug) + dev_info(dev, "shutdown\n"); + dev->driver->shutdown(dev); + } + + device_unlock(dev); + if (parent) + device_unlock(parent); + + put_device(dev); + put_device(parent); + + spin_lock(&devices_kset->list_lock); +} + /** * device_shutdown - call ->shutdown() on each device to shutdown. */ void device_shutdown(void) { - struct device *dev, *parent; + struct device *dev; wait_for_device_probe(); device_block_probing(); @@ -4741,52 +4802,7 @@ void device_shutdown(void) dev = list_entry(devices_kset->list.prev, struct device, kobj.entry); - /* - * hold reference count of device's parent to - * prevent it from being freed because parent's - * lock is to be held - */ - parent = get_device(dev->parent); - get_device(dev); - /* - * Make sure the device is off the kset list, in the - * event that dev->*->shutdown() doesn't remove it. - */ - list_del_init(&dev->kobj.entry); - spin_unlock(&devices_kset->list_lock); - - /* hold lock to avoid race with probe/release */ - if (parent) - device_lock(parent); - device_lock(dev); - - /* Don't allow any more runtime suspends */ - pm_runtime_get_noresume(dev); - pm_runtime_barrier(dev); - - if (dev->class && dev->class->shutdown_pre) { - if (initcall_debug) - dev_info(dev, "shutdown_pre\n"); - dev->class->shutdown_pre(dev); - } - if (dev->bus && dev->bus->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->bus->shutdown(dev); - } else if (dev->driver && dev->driver->shutdown) { - if (initcall_debug) - dev_info(dev, "shutdown\n"); - dev->driver->shutdown(dev); - } - - device_unlock(dev); - if (parent) - device_unlock(parent); - - put_device(dev); - put_device(parent); - - spin_lock(&devices_kset->list_lock); + device_shutdown_one_locked(dev); } spin_unlock(&devices_kset->list_lock); } -- 2.39.2