Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5368376pxu; Wed, 21 Oct 2020 23:39:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+e6z8rbDO2/SGgx+AQ+T4kvT+p6BMD9nelKRzsmyddVPzH+bVT4IRL4bhyMdnQG4rnzxv X-Received: by 2002:a17:907:206e:: with SMTP id qp14mr905813ejb.76.1603348767504; Wed, 21 Oct 2020 23:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603348767; cv=none; d=google.com; s=arc-20160816; b=Us6mhkFKJbD1VNyIIDK6qr2w0OUjFtMxbegnrdO0Etl1jrT5TwMeexDK0O8BItJTLQ Gqr7UYFs/KSPLyL776zPXJc2xI2euIz79uyEzvj204OL3ZUlj6AJ0pOd3Z5RqR7BrloJ 73pAeN4OS27yBBgEec+6opFaIljBNq4vZaEz7TjuDuK5wsu9ad6Ci1fgFrpSciFnR0Lf 5qpy9n7Nhnz28vCV7zTJyA6KIrmA5NzTERAA4WI26X76F8UZMqpDzutnMVVVBICBU/BQ EBa+Wv79YmJSek+Dy68s2LO3PpWRUIzHEeI2N7oNqgKewuJvAgn5bntZj0c39TPbCrqX nHSQ== 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=CaiTIZYIN0hvF7zpjJJYhHEQbY/haeHSnMWXWFG8/As=; b=jC7Fe2FGHEX9s71/2xiSeZM/Hz0UJlP3Xi6U3l0/Gar9z4yDgWaTfyVkyNWO7ouK0E IUz0PXMLSBnpN+Pfgvnw+CO8UrbvtZbUMlCtbGFXkh6qsQD6XM1/KHSGwS/vhCB+ljiN ckJvbejSs/DUCipYU5jTKt7v5B9U3earqofLABHftN0+I1sU9S3whtKO1PXIijSV+Yrf 2AKLWesMUV8C2VpoVzOINRuHB8g16xT85boKmh2ubKmPOg289Ny9bRW1cGNeLBMEAnbr KhSkjv28mhAdXfw93ogPCcHdONbZ/PnMIv4eFKNGSYB5PQ4i0bVZTCTJHO6Gxr7OXoIe 5pCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t11si327814ejf.423.2020.10.21.23.39.05; Wed, 21 Oct 2020 23:39:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504794AbgJUTOd (ORCPT + 99 others); Wed, 21 Oct 2020 15:14:33 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:49740 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409566AbgJUTOc (ORCPT ); Wed, 21 Oct 2020 15:14:32 -0400 Received: from 89-77-60-66.dynamic.chello.pl (89.77.60.66) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.491) id a6fe99e340b4f9a8; Wed, 21 Oct 2020 21:14:30 +0200 From: "Rafael J. Wysocki" To: Greg Kroah-Hartman Cc: Linux PM , LKML , Lukas Wunner , Saravana Kannan , Xiang Chen Subject: [PATCH 3/3] PM: runtime: Resume the device earlier in __device_release_driver() Date: Wed, 21 Oct 2020 21:14:18 +0200 Message-ID: <1708806.S9fAqql2gf@kreacher> In-Reply-To: <6543936.FbWAdBN1tG@kreacher> References: <6543936.FbWAdBN1tG@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Since the device is resumed from runtime-suspend in __device_release_driver() anyway, it is better to do that before looking for busy managed device links from it to consumers, because if there are any, device_links_unbind_consumers() will be called and it will cause the consumer devices' drivers to unbind, so the consumer devices will be runtime-resumed. In turn, resuming each consumer device will cause the supplier to be resumed and when the runtime PM references from the given consumer to it are dropped, it may be suspended. Then, the runtime-resume of the next consumer will cause the supplier to resume again and so on. Update the code accordingly. Signed-off-by: Rafael J. Wysocki Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support") Cc: All applicable # All applicable --- drivers/base/dd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Index: linux-pm/drivers/base/dd.c =================================================================== --- linux-pm.orig/drivers/base/dd.c +++ linux-pm/drivers/base/dd.c @@ -1117,6 +1117,8 @@ static void __device_release_driver(stru drv = dev->driver; if (drv) { + pm_runtime_get_sync(dev); + while (device_links_busy(dev)) { __device_driver_unlock(dev, parent); @@ -1132,8 +1134,6 @@ static void __device_release_driver(stru return; } - pm_runtime_get_sync(dev); - driver_sysfs_remove(dev); if (dev->bus)