From patchwork Thu May 11 07:34:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 92415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4189171vqo; Thu, 11 May 2023 00:53:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56gX8/PRLxSlGyLwqG8QEVVBslH3pTFbyc4gdJOJzJIeTTChBCEfT1MfEScmWaTYWqIoSQ X-Received: by 2002:a05:6a21:7891:b0:101:209e:bc57 with SMTP id bf17-20020a056a21789100b00101209ebc57mr12373333pzc.50.1683791637930; Thu, 11 May 2023 00:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683791637; cv=none; d=google.com; s=arc-20160816; b=tUcbIsNTz9nixh4S/G6x361zNWQesYXRKumsThGCVmkdj2rvikiewh4NPEa3GZAXug bN7qoRUrmPkK+8BaDSQIZXchbDHU7whdBzuSMI4ufx1eooiZnL8oZedln/oFFr4CXYZh 5+GZQuZXJo4Zo5WvwvclxdodxYwuGVVqiDoluAANNiXr6Gb20K2vSYNmt4G4n/g5fn4i 1EKBLM0dMfI3GKyvH5hUX71wAbTdpLXSrZzuI5FT+1qAAVDqpOlD9VKbEqFZzh0h9/6E /b28b66Tc/+twDofIMTcWM1clU9fn4o9Eqi7E3VzuCax91zDFRTaiW0FlqyOVXEwvBj3 T58Q== 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 :message-id:date:subject:cc:to:from; bh=5XR6+55yi4tPNhQ/iD4NXvad20nbO2OjrT9N59wMiGE=; b=1CJrrBL/6etSK6Cpy+2JkpdZ/QULNJVdYtwK0TnpukAdVCK+CzM7oBStZec22c8lfP wFINYsSnKeebI4b2STea9DYl6Hc0NBRzYiZdzvTGOp0D2Sa+LGhZJtLHn7KHIoT9K+ue 3s7ov3YRML1l7n0qdXcI1V67KFTvY34YNAjCNGIBRfyCNdJAkBvQkLIlmvQB8a9DZSWO VXsOcDNVq9V4vYLeUAigmW8j7VfJRJ7GyqwsrHyJdtgZlLSFGEGHmzTMmR/iOWYJ9CL9 WRIHyxQLt5oPhVONKGn3WkuqJX/fDnvpod/iZ7DuB1x5LLUZon+VK5YlxHkJWBPFIx1L FOJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a189-20020a624dc6000000b0064583a79521si7357107pfb.283.2023.05.11.00.53.45; Thu, 11 May 2023 00:53:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbjEKHfV (ORCPT + 99 others); Thu, 11 May 2023 03:35:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237717AbjEKHfH (ORCPT ); Thu, 11 May 2023 03:35:07 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5533F9EE5 for ; Thu, 11 May 2023 00:34:37 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1px0os-0007Zn-TE; Thu, 11 May 2023 09:34:34 +0200 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1px0os-002fr1-2v; Thu, 11 May 2023 09:34:34 +0200 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1px0or-003LJM-58; Thu, 11 May 2023 09:34:33 +0200 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove() Date: Thu, 11 May 2023 09:34:28 +0200 Message-Id: <20230511073428.10264-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1613; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=inxu00lxAvQhhTdGwdmmOXbixsATQzMqe2CB3zBDu5I=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBkXJqDyBlNnJ+V0dwc6hrHJ43dopD/xjtOQqTyu VX7vDqJ/uKJATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZFyagwAKCRCPgPtYfRL+ TmGdB/9Mu2bv39+Vfrpo+4ssj59lgz65Oc97qu74DfG3s7/lLI0AsUWxoEOuE++iqeatemZlwvH 4QURYl7UbHzj+pUAfDx6gxTzCmUqPd/40uC35U61Ah+h1YN3hMLRKmmtDw67FjeqsX1i7G+rqI9 8jTXKOk427HvZPHsX3nuyWBkUqhIRwdEEh3DPBbngoRQYkQkJZV2dxBQ9warhDnRbYqV7Nv19o+ Ielf3E3CW/ZhfnJIeTHGcviYojHygYaa88y0NgKThdu9e1h0meTIiCQR7oEr8OBhifGj6HIDB/M R+QHgkZwc8FwpmGXfN80j4gqIkQZVq59jdg6TpWwqhSMwncO X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765583500160633111?= X-GMAIL-MSGID: =?utf-8?q?1765583500160633111?= Many drivers that use runtime PM call pm_runtime_get_sync() or one of its variants in their remove callback. So calling pm_runtime_put_sync() directly before calling the remove callback results (under some conditions) in the driver's suspend routine being called just to resume it again afterwards. So delay the pm_runtime_put_sync() call until after device_remove(). Confirmed on a stm32mp157a that doing echo 4400e000.can > /sys/bus/platform/drivers/m_can_platform/unbind (starting with a runtime-pm suspended 4400e000.can) results in one call less of m_can_runtime_resume() and m_can_runtime_suspend() each after this change was applied. Signed-off-by: Uwe Kleine-König Reviewed-by: Rafael J. Wysocki --- Hello, side note: To test I added a dev_info() to m_can_runtime_resume() and m_can_runtime_suspend(). I was surprised that directly after boot I had: # dmesg | grep -E '4400e000.can: m_can_runtime_(resume|suspend)' | wc -l 15 I didn't go down that rabbit hole to debug this. Best regards Uwe drivers/base/dd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 9c09ca5c4ab6..d97f6b1486d1 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -1267,10 +1267,10 @@ static void __device_release_driver(struct device *dev, struct device *parent) bus_notify(dev, BUS_NOTIFY_UNBIND_DRIVER); - pm_runtime_put_sync(dev); - device_remove(dev); + pm_runtime_put_sync(dev); + if (dev->bus && dev->bus->dma_cleanup) dev->bus->dma_cleanup(dev);