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: 122929 Delivered-To: patches@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4574642qgn; Fri, 29 Dec 2017 03:37:23 -0800 (PST) X-Received: by 10.46.23.20 with SMTP id l20mr23423758lje.25.1514547443025; Fri, 29 Dec 2017 03:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514547443; cv=none; d=google.com; s=arc-20160816; b=qIaUpqq0WETnHD8xDisfbkvDl4yUjm2AYgLlTebaceMVd+VcrbpNm2fs3CIpX3571h K+CH/kA+8mzddRT10Amq7b0cV18Pm5YHbSFSQsJQXtOQrRa292yz6OrUuDIM1ri/WR7e uByYJJaIX1KEdSCHbwSDxb+xszy1drrIpFKo7keLRegSjXmurnnJyiydrWq8HUpnzYI/ ejr1uU5Nin/acWzzCpOW3RyveG7TyKblvZ69waTsj+aMt9XxVl5EbWBcdwz/SfQZ2Zed CXJdJIHnf9E1k+i2Mv+dyTTNLIhZqirQabL4Ac6Zp/Hop9UTTGLtWam/w4FqrnwQa6G4 isyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=jeSqjtzB2DBp2xANqlxHzuTbpbqPELPc77QlkQt6RsU=; b=MsgTBaYmvwhvDDE8UciBaFTK0y/Vogv+KXn0iUy6h9Kb6iCQHXA5Sz+3GfQIe2kwC6 n/m8Au4+NZVAeUrzxfrf4v6y9TunoJaf+pcw0Nl2wC4GW4NkVlAL/WbToAlXkC242i+k enCULRHnY1h50oBOFD86tNicuFxj1HRemmu42N3eKcF7RmGoSxsq+byT64/ingJQhopE eS2wstnbn/oKuHs9sCwkzteLO8KdQLoIjXCrCGoRYJ2RSbq9Vhr6PSLAeefoLw48pSEf 4fndcEzWVhjTWmFFenrnWEXFgb4RpQsM8W72+/XCZxKFoNUSUpqa7k/3zFt6cdZbjE21 IWmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EluEPxjw; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f79sor3808430lfi.39.2017.12.29.03.37.22 for (Google Transport Security); Fri, 29 Dec 2017 03:37:23 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EluEPxjw; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=LD12La2GSJ7hjQu+EsbtiWO0jm4y5vpMt1adaDZbAHwUjTNzjqBDILO57kAu1KpQ9F K26eyqUmBT9M+8mFg7LViphko+t1y7FjQ7M+2ROsZ29Cw0Y7SCeNPnqR2HnTjbYZHZxL U7jBx8x4hb4Hy9P4ahaVs0RaIn6r/avMM56obMMdSUfgwg/y2RKjftAnoFgt27IFDI1v p7pVgnXLO04YRQD725ODrlnQT5/oBeVk5Ra8lLIO7jlydnna+04m8khcreYFAU90zK5P Zao8SrdmJkLVpbZPggjA3tybVjYuxlbMcWxgUB9aKCKKSFdDtrp4pfYtJkI9mb4YU21O E0mA== X-Gm-Message-State: AKGB3mKW6P9VF2EpDba02gXzvZxn1QEYAOXmPWepbJU3pijzcn+nbR74 U0Ryr8PDdR2RQJsrFYjjCUeaXaiX 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) Return-Path: 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> 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(+) -- 2.7.4 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 */