From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5645FC55179 for ; Thu, 22 Oct 2020 15:38:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFDA52463F for ; Thu, 22 Oct 2020 15:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S368674AbgJVPi2 (ORCPT ); Thu, 22 Oct 2020 11:38:28 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:60762 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S368664AbgJVPiZ (ORCPT ); Thu, 22 Oct 2020 11:38:25 -0400 Received: from 89-64-87-167.dynamic.chello.pl (89.64.87.167) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.491) id 407eec497ad3e201; Thu, 22 Oct 2020 17:38:23 +0200 From: "Rafael J. Wysocki" To: Greg Kroah-Hartman Cc: Linux PM , LKML , Lukas Wunner , Saravana Kannan , Xiang Chen Subject: [PATCH update 3/3] PM: runtime: Resume the device earlier in __device_release_driver() Date: Thu, 22 Oct 2020 17:38:22 +0200 Message-ID: <7787143.pm0zn309lf@kreacher> In-Reply-To: <1708806.S9fAqql2gf@kreacher> References: <6543936.FbWAdBN1tG@kreacher> <1708806.S9fAqql2gf@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 --- This update adds a missing pm_runtime_put() before a return statement. Thanks! --- drivers/base/dd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 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); @@ -1128,12 +1130,12 @@ static void __device_release_driver(stru * have released the driver successfully while this one * was waiting, so check for that. */ - if (dev->driver != drv) + if (dev->driver != drv) { + pm_runtime_put(dev); return; + } } - pm_runtime_get_sync(dev); - driver_sysfs_remove(dev); if (dev->bus)