From patchwork Wed Nov 8 09:11:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 118220 Delivered-To: patches@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5036803qgn; Wed, 8 Nov 2017 01:11:10 -0800 (PST) X-Received: by 10.46.92.136 with SMTP id q130mr710330ljb.78.1510132270066; Wed, 08 Nov 2017 01:11:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510132270; cv=none; d=google.com; s=arc-20160816; b=JuGL3f/MDLyabk0CSfgLcE2Sf0ppv2KjHUjmNsayOJ6ASjQZ+1zfVigdF1e6H74GcI lLXkjDlWHAiVM8r/SeO8GW4N4kNbIUZ3nhkrsi3unX5w5rDegSpFMacWZZUzWTpVAbIW O2qyDi5qBnVIqSDYjLElnjvBFYWhffj8fTM8pOVwoCKkTq8qtNyrGAtfg7PRwvuffrR+ kL9tl2Y3OJ7WwB/IVydX3NleKyxfNIC3kbmUvhb+Bs4ONGJ1VuIHP1I/PMnnml0x7B05 ehD/PeoDV7zPfbelCnhAuTCk6n6IdCgZOZw3hB9oTShai1TwCvqx0AHa4UYAPcg/1Dm9 u0Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=bSXhvdivl660tHXxdN299lZ7kJgHw+2BFSuYY5246KQ=; b=GDiYCrRDyFk7MBygGq553bTyxrjxZKquYMxlMoMOBtXHwOM7vOSGLh5daLcT0SpbLN 4UsWyudanB/7kzk0g/57LoItuskT5DY1/JlS3qBwxLNJqkZjdv6/azwk/RaonVMXl72R 05ErrNXVHzZbeWCPi+dsKa/4zQpcqjxWHWzDnqT8aUnBvydcv08c192nCi6xRISbE4MD Euu6eKNNR00Xgw7e38Qwq//2aDK/VhIpYSfrC0a6UezJbnIDzet/4OQ7AsSIUJjry146 3U/7nY594DkJu2gw/OLfuu5+92xc1REkzlNI0gUusP8ZWqS9cQ9Sx3t6FchTN9wP4BIX 6Crg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XyHK91lh; 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 g28sor619886lfi.66.2017.11.08.01.11.09 for (Google Transport Security); Wed, 08 Nov 2017 01:11:09 -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=XyHK91lh; 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; bh=bSXhvdivl660tHXxdN299lZ7kJgHw+2BFSuYY5246KQ=; b=XyHK91lhisinNBb4XpjvS+TmczYlXv/9lwCnzHH08/8X0bOBi14/8LLunD47dz/p80 qEdYexGaPSOWiujR1XWpmgFgBuaH+77es0mONmZ/42EUqU3vNBE3RVdpe/hhy8tLmmVu 7/kcXB2qIIqryxRrhjG+vjyyGAYzML2DZ6CTo= 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; bh=bSXhvdivl660tHXxdN299lZ7kJgHw+2BFSuYY5246KQ=; b=fBLH3sP8okieaRCoR1QxvNNrt4jScC+x0UYyRvToUxhhUlGQQxH8eUX+WFskeOy70/ 2O5qUt1gHM/XoyRyu3XDkjWFGn9jXKJ9QDfqkjyzUB3FXAP6mtWqsbLs4M8KHpz7DZ7A e8siaJ32MOJ5avHQKM+b5mNFx2+AqlIoox+qEQGbk/rXNUfZUQY2jybG4oMlZFmCG5rD paCGIlf6vtzxZdS4eE0/7L56ZSDopifeUvyGfFtX3SSSdpQsLFFnqYVMwfizhMLWvJyP SrGkax/ABAhM4mYaLNehJh3pHJ10LmL1EIQFzYPLh/ynUnuohCHKDNomy9hORc1D/Nlc FCbg== X-Gm-Message-State: AJaThX4p2TqumO7k4PfqMniRLSZSeHgttaST0UwOjihGg+Cw4WykR+3k gWeUpbsBKqs33/cT43j66wo4WkYq X-Google-Smtp-Source: AGs4zMY0wMFLihkNeIZO1ZOhwq8qIzdFWCdwbVvM2Y0C6keJLO3YuAxEJMctaAriuOiBql3DoiPl6Q== X-Received: by 10.25.115.196 with SMTP id h65mr561890lfk.203.1510132269401; Wed, 08 Nov 2017 01:11:09 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id 73sm673099lja.84.2017.11.08.01.11.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Nov 2017 01:11:08 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Kevin Hilman , Viresh Kumar , Geert Uytterhoeven , Ulf Hansson Subject: [PATCH] PM / Domains: Fix genpd to deal with drivers returning 1 from ->prepare() Date: Wed, 8 Nov 2017 10:11:02 +0100 Message-Id: <1510132262-21928-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 During system-wide PM, genpd relies on its PM callbacks to be invoked for all its attached devices, as to deal with powering off/on the PM domain. In other words, genpd is not compatible with the direct_complete path, if executed by the PM core for any of its attached devices. However, when genpd's ->prepare() callback invokes pm_generic_prepare(), it does not take into account that it may return 1. Instead it treats that as an error internally and expects the PM core to abort the prepare phase and roll back. This leads to genpd not properly powering on/off the PM domain, because its internal counters gets wrongly balanced. To fix the behaviour, allow drivers to return 1 from their ->prepare() callbacks, but let's return 0 from genpd's ->prepare() callback in such case, as that prevents the PM core from running the direct_complete path for the device. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 24e39ce..0c80bea 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1008,7 +1008,7 @@ static int genpd_prepare(struct device *dev) genpd_unlock(genpd); ret = pm_generic_prepare(dev); - if (ret) { + if (ret < 0) { genpd_lock(genpd); genpd->prepared_count--; @@ -1016,7 +1016,8 @@ static int genpd_prepare(struct device *dev) genpd_unlock(genpd); } - return ret; + /* Never return 1, as genpd don't cope with the direct_complete path. */ + return ret >= 0 ? 0 : ret; } /**