From patchwork Mon Oct 17 18:17:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 77797 Delivered-To: patches@linaro.org Received: by 10.140.97.247 with SMTP id m110csp518009qge; Mon, 17 Oct 2016 11:17:18 -0700 (PDT) X-Received: by 10.25.43.12 with SMTP id r12mr16849872lfr.104.1476728238870; Mon, 17 Oct 2016 11:17:18 -0700 (PDT) Return-Path: Received: from mail-lf0-x233.google.com (mail-lf0-x233.google.com. [2a00:1450:4010:c07::233]) by mx.google.com with ESMTPS id h10si13828509lfe.220.2016.10.17.11.17.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Oct 2016 11:17:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 as permitted sender) client-ip=2a00:1450:4010:c07::233; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::233 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-lf0-x233.google.com with SMTP id x79so307619596lff.0 for ; Mon, 17 Oct 2016 11:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tRZRmcaMnsCw9HW6CUnuU2osK4mIrrKTwDLthg/njBE=; b=gxgI3qrnfYW3YIoXfk/TWbbkdVqbXciHDgLwfJNCy3sjD0By9gKrr70/DIAi4VL2CX JQi790MRfQ3rS6EWtGjnFHhyNqPzmkdVPmd6bBKbZa7kGg3+91fTZ8PpOhf2/HsOu6Xl 70QiEA6AKYaBFK0vlfWkI5986yr2Ad5D6sdBE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tRZRmcaMnsCw9HW6CUnuU2osK4mIrrKTwDLthg/njBE=; b=KlxFdd++pV/mTQVbGakrHmr0XTNQDKuW19Aneiz48jHTjILc+XmvXmsJW3c1Y5zjQd SFV90BI9r+JLITRpFFJyR3tIEFH/egJo4lEgHbKpxXlopbpTFNju1VELemva8altqLWj 0OM4ambjxyLt14st0VgHZiBYKlKacbC55cGfXNnN5aqHbVkwkU7GxRD1SgcKcwBywo38 6vXkURMGJ/yJRPFd46a0OG4nEzhTOtIl3jgGOnS6Aw6uisXyDtGa8gIRHW7jHLfVQeG0 W+XGAZc55PBbLAvKO+WA2h2DhiH8yMxzsCMy+58C5QvO2ZUwU7X+HEp6d6n62zVFQcRD bBUg== X-Gm-Message-State: AA6/9RkLlfjETTwiTZj7B6du8lRoXkWhTJg8HJ9WhJ6qVRXUpb9lSNbxQ7ON0eJEmTwYd2hzZp4= X-Received: by 10.25.87.17 with SMTP id l17mr16675926lfb.153.1476728238431; Mon, 17 Oct 2016 11:17:18 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-221-67.na.cust.bahnhof.se. [155.4.221.67]) by smtp.gmail.com with ESMTPSA id r20sm8230251lfr.19.2016.10.17.11.17.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 11:17:17 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Alan Stern , Ulf Hansson , linux-pm@vger.kernel.org Cc: Len Brown , Pavel Machek , Kevin Hilman , Geert Uytterhoeven , Lina Iyer , Jon Hunter , Marek Szyprowski , Linus Walleij Subject: [PATCH 4/4] PM / Runtime: Don't allow to suspend a device with an active child Date: Mon, 17 Oct 2016 20:17:01 +0200 Message-Id: <1476728221-26530-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1476728221-26530-1-git-send-email-ulf.hansson@linaro.org> References: <1476728221-26530-1-git-send-email-ulf.hansson@linaro.org> When resuming a device in __pm_runtime_set_status(), the prerequisite is that its parent must already be active, else an error code is returned and the device's status remains suspended. When suspending a device there is no similar constraints being validated. Let's change this to make the behaviour consistent, by not allowing to suspend a device with an active child, unless it has been explicitly set to ignore its children. Signed-off-by: Ulf Hansson --- drivers/base/power/runtime.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 1.9.1 Reviewed-by: Linus Walleij diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index f47a345..6f946a3 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1028,7 +1028,17 @@ int __pm_runtime_set_status(struct device *dev, unsigned int status) goto out_set; if (status == RPM_SUSPENDED) { - /* It always is possible to set the status to '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;