From patchwork Fri Dec 29 11:37:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 10137013 X-Patchwork-Delegate: geert@linux-m68k.org 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 C3A496037D for ; Fri, 29 Dec 2017 11:37:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B18EB2DF16 for ; Fri, 29 Dec 2017 11:37:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A69672DF17; Fri, 29 Dec 2017 11:37:26 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 4BFB42DF14 for ; Fri, 29 Dec 2017 11:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755664AbdL2LhZ (ORCPT ); Fri, 29 Dec 2017 06:37:25 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:37313 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755587AbdL2LhY (ORCPT ); Fri, 29 Dec 2017 06:37:24 -0500 Received: by mail-lf0-f68.google.com with SMTP id f3so11720752lfe.4 for ; Fri, 29 Dec 2017 03:37:23 -0800 (PST) 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=jeSqjtzB2DBp2xANqlxHzuTbpbqPELPc77QlkQt6RsU=; b=EluEPxjwD8gsHte8MkyuIsRRpQ1mfsDQfG5fPBV9bHGpR5W7wloO0Z/MSROFeb3tmG yuFbc66RkpPycp+Kix4aFyVvCuuCiF0Qc70QhDYBglFe7Uw1O79RKHI4yAy8dn5uAR9i lB47NAyTXjCGOelzcRXmUtEwNzlUghSvUeyko= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jeSqjtzB2DBp2xANqlxHzuTbpbqPELPc77QlkQt6RsU=; b=odRzRvtQOCSXVJtxQTc0PWe3os1dxhUosdvAnJ95Md+gXxmQp1aNTRbZen70X1CCo2 9hitBX9wfPzFDJGILQqZdgwLC5e9lUmSqd2E0KQCfBOjZ7x3OzS+HAbk7oDTjXunfiCW OFo4P4t29Z1brpaTWcIQ7tcVw7l05EfALH1qGRAp7+eCfZemJYzr9nwX8+RcQDWg4aC+ igkst/B+jFh6QKOK6LiNV2JYXCrGX/eDsEURqlgC393ttgNxCb9KiBL4n1THc5ozjOY8 bfUywBzUWCeyRSiyIw67xNySnQjIIf3YrJ6F3iBwQbgL7DaREgb/qlaENwDlkL3Kg1fS EGfw== X-Gm-Message-State: AKGB3mLmBgInshe6hWSjad3y4WZVO7ZExx2/J4MTUAslgRudiX/ayQdj 1ubBujSgO/OftQ/qkfRf/FrI1Q== X-Google-Smtp-Source: ACJfBovEQwxpeJHuLLimKgAque7caoR3bHXOHQNLYavbHuq+hz82ImfcJD3npBSCXcDBfzQAoyDv3g== X-Received: by 10.25.150.137 with SMTP id y131mr19534724lfd.91.1514547442641; Fri, 29 Dec 2017 03:37:22 -0800 (PST) Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id r74sm7280469ljb.28.2017.12.29.03.37.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Dec 2017 03:37:22 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Kevin Hilman , Viresh Kumar , Geert Uytterhoeven , Simon Horman , Niklas Soderlund , Vincent Guittot , linux-renesas-soc@vger.kernel.org, Ulf Hansson Subject: [PATCH v2 4/4] PM / core: Print warn if device gets enabled as wakeup source during sleep Date: Fri, 29 Dec 2017 12:37:03 +0100 Message-Id: <1514547423-18965-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514547423-18965-1-git-send-email-ulf.hansson@linaro.org> References: <1514547423-18965-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In general, wakeup settings are not supposed to be changed during any of the system wide PM phases. The reason is simply that it would break guarantees provided by the PM core, to properly act on active wakeup sources. However, there are exceptions to when, in particular, disabling a device as wakeup source makes sense. For example, in cases when a driver realizes that its device is dead during system suspend. For these scenarios, we don't need to care about acting on the wakeup source correctly, because a dead device shouldn't deliver wakeup signals. To this reasoning and to help users to properly manage wakeup settings, let's print a warning in cases someone calls device_wakeup_enable() during system sleep. Signed-off-by: Ulf Hansson --- drivers/base/power/main.c | 4 ++++ drivers/base/power/wakeup.c | 4 ++++ include/linux/pm.h | 1 + 3 files changed, 9 insertions(+) diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 1327726..6b0d312 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -1030,6 +1030,8 @@ static void device_complete(struct device *dev, pm_message_t state) callback(dev); } + dev->power.may_set_wakeup = dev->power.can_wakeup; + device_unlock(dev); pm_runtime_put(dev); @@ -1747,6 +1749,7 @@ static int device_prepare(struct device *dev, pm_message_t state) device_lock(dev); + dev->power.may_set_wakeup = false; dev->power.wakeup_path = false; if (dev->power.no_pm_callbacks) { @@ -1775,6 +1778,7 @@ static int device_prepare(struct device *dev, pm_message_t state) if (ret < 0) { suspend_report_result(callback, ret); pm_runtime_put(dev); + dev->power.may_set_wakeup = dev->power.can_wakeup; return ret; } /* diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index cb72965..5445bea 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c @@ -268,6 +268,9 @@ int device_wakeup_enable(struct device *dev) if (!dev || !dev->power.can_wakeup) return -EINVAL; + if (!dev->power.may_set_wakeup) + dev_warn(dev, "don't enable as wakup source during sleep!\n"); + ws = wakeup_source_register(dev_name(dev)); if (!ws) return -ENOMEM; @@ -413,6 +416,7 @@ void device_set_wakeup_capable(struct device *dev, bool capable) return; dev->power.can_wakeup = capable; + dev->power.may_set_wakeup = capable; if (device_is_registered(dev) && !list_empty(&dev->power.entry)) { if (capable) { int ret = wakeup_sysfs_add(dev); diff --git a/include/linux/pm.h b/include/linux/pm.h index ebc6ef8..106fb15 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -606,6 +606,7 @@ struct dev_pm_info { struct list_head entry; struct completion completion; struct wakeup_source *wakeup; + bool may_set_wakeup:1; bool wakeup_path:1; bool syscore:1; bool no_pm_callbacks:1; /* Owned by the PM core */