From patchwork Sun Nov 12 00:27:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 10054579 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6E4DE6028A for ; Sun, 12 Nov 2017 00:27:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B767299C8 for ; Sun, 12 Nov 2017 00:27:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BC9329AFE; Sun, 12 Nov 2017 00:27:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D2DB299C8 for ; Sun, 12 Nov 2017 00:27:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752208AbdKLA1l (ORCPT ); Sat, 11 Nov 2017 19:27:41 -0500 Received: from cloudserver094114.home.net.pl ([79.96.170.134]:44956 "EHLO cloudserver094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752199AbdKLA1k (ORCPT ); Sat, 11 Nov 2017 19:27:40 -0500 Received: from 79.184.254.73.ipv4.supernova.orange.pl (79.184.254.73) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.82) id ed5b30956ca06df5; Sun, 12 Nov 2017 01:27:39 +0100 From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Ulf Hansson , Greg Kroah-Hartman , Alan Stern Subject: [PATCH] PM / runtime: Drop children check from __pm_runtime_set_status() Date: Sun, 12 Nov 2017 01:27:30 +0100 Message-ID: <1713438.irjm9MTSvo@aspire.rjw.lan> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki The check for "active" children in __pm_runtime_set_status(), when trying to set the parent device status to "suspended", doesn't really make sense, because in fact it is not invalid to set the status of a device with runtime PM disabled to "suspended" in any case. It is invalid to enable runtime PM for a device with its status set to "suspended" while its child_count reference counter is nonzero, but the check in __pm_runtime_set_status() doesn't really cover that situation. For this reason, drop the children check from __pm_runtime_set_status() and add a check against child_count reference counters of "suspended" devices to pm_runtime_enable(). Signed-off-by: Rafael J. Wysocki Reviewed-by: Ulf Hansson Reviewed-by: Johan Hovold --- drivers/base/power/runtime.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) Index: linux-pm/drivers/base/power/runtime.c =================================================================== --- linux-pm.orig/drivers/base/power/runtime.c +++ linux-pm/drivers/base/power/runtime.c @@ -1101,29 +1101,13 @@ int __pm_runtime_set_status(struct devic goto out; } - if (dev->power.runtime_status == status) + if (dev->power.runtime_status == status || !parent) goto out_set; if (status == RPM_SUSPENDED) { - /* - * It is invalid to suspend a device with an active child, - * unless it has been set to ignore its children. - */ - if (!dev->power.ignore_children && - atomic_read(&dev->power.child_count)) { - dev_err(dev, "runtime PM trying to suspend device but active child\n"); - error = -EBUSY; - goto out; - } - - if (parent) { - atomic_add_unless(&parent->power.child_count, -1, 0); - notify_parent = !parent->power.ignore_children; - } - goto out_set; - } - - if (parent) { + atomic_add_unless(&parent->power.child_count, -1, 0); + notify_parent = !parent->power.ignore_children; + } else { spin_lock_nested(&parent->power.lock, SINGLE_DEPTH_NESTING); /* @@ -1307,6 +1291,12 @@ void pm_runtime_enable(struct device *de else dev_warn(dev, "Unbalanced %s!\n", __func__); + WARN(dev->power.runtime_status == RPM_SUSPENDED && + !dev->power.ignore_children && + atomic_read(&dev->power.child_count) > 0, + "Enabling runtime PM for inactive device (%s) with active children\n", + dev_name(dev)); + spin_unlock_irqrestore(&dev->power.lock, flags); } EXPORT_SYMBOL_GPL(pm_runtime_enable);