From patchwork Thu Aug 29 14:48:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 172629 Delivered-To: patches@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2333754ily; Thu, 29 Aug 2019 07:48:11 -0700 (PDT) X-Received: by 2002:a19:6001:: with SMTP id u1mr6520562lfb.50.1567090091784; Thu, 29 Aug 2019 07:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567090091; cv=none; d=google.com; s=arc-20160816; b=IpQSyH7uJtXaF4/s8/smK7Y5IfUU29jBpFJnNtLobfgEoddBjGggaX/qZnf55Do1xH HxllV/cmWF63du8cm+F5E5BDo36+hqgP/w7B+NrOHcyDx+gMGo7lQXV5Nu/tX1c0ELVU u4WqHHihP73ZOl7DqRlcgVb5w3UqSjy4hh8/4suiPt7qzdevdiTnLP2Ow/hNquQbQb5D xigz+QKtWe5DAZ5xPQg6taBbaBMSVeYGI2XzXj5Y1gfX4PiIjIinOkoBajSFSzazF7r+ paFTfA5XYDtoY7WThGxko5FRHz23YhM4bzsQWaFFiRxEsBVVKhlNrPwYRJDXP9LP5XPe hi9w== 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; bh=IDKt2aAXkJXSDAZlnyGOh55R8DuS2AbznpFvj37Ib1E=; b=DU0smraHJ2KZoa6dZZ4hcISZ/zign5/lOKqexGXnZZqHqOPtDLrKC2bLr3ZwciTi80 aBXOf06YBqoo/BmE+b9PgOLE35hwGiD5kv8HlX7oA/DLtrjdTsACK0gzBa9wfwUXAdCK VYr2uP1auMXBybV7tcG/GrO6bmYlbvFpX6VTGAhrvwxUygSbla2W+1jKPiXvHQMj2xtr hrIgj8sGjBYk5AikAtqhwZZ4hS84HIqkpajZxJC4Ef+0Mp6eUDxt8ckz1CjjA3FqcFLk 5RN09XBFoAm8+IGLPfnSQeESh77GFTKumHoDKwd/NArMJ37FM+qvg/GVaUXWW65FUkt3 lsow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DbPcEctP; 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 f20sor909505lfm.66.2019.08.29.07.48.11 for (Google Transport Security); Thu, 29 Aug 2019 07:48:11 -0700 (PDT) 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=DbPcEctP; 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=IDKt2aAXkJXSDAZlnyGOh55R8DuS2AbznpFvj37Ib1E=; b=DbPcEctP3Ry5pepk3axgMtKQCCNHSi2sXy55WR7ENYh5OPznWwkgs+CY913L6atlLm zoJvIjSWRSUtf6HBsx8PfS9sg2VVDspEkoMasKryurZxuSlZxO8k3b+uvw1dMCp9oV3D gu5IFVnff7uj5QNLDvIfOYfenZSuKXjYkEa2vbLpivgl+7YVjqhX2Ihg1P2ejZebwxr8 TvnUMaOdWGbKIpGcUQZeiLgWO5X13nsIX9oXwSpQhLl7ClEu0T1I0RximGJxmXh9ug14 JNnq25JG8n+bndS54REDJqXpykUUq1xIm4oLb6+IxvgrYXNpj33xAX792kNnOkeUkzF5 /Jag== 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=IDKt2aAXkJXSDAZlnyGOh55R8DuS2AbznpFvj37Ib1E=; b=DV4hVnqcgg1GfVFcb6IBsYDNLBT0Cx5Jo+6h+NdbR0q+m/a7igpNqWLFm7719md+iM wyYUohF+PqT0MT4fV3TuOqLWE1t9uKk6BsJJXjwKj+4/MDMxfh5831mxb8CtWfY8xujQ zVLbvtABXwdSlT4K/MHDUPGzvfSBEGrOvQ5L3RhFwMzDQWJxhlXEeLggRsVUrHfRP+Be Zjd3NvgKBfKCzumb1R2gwisE9HHNyLa9GW7nFXs2bsyn7qiEIFzxBSWAki6WJJC6xLqW nEVCddc6Zl482SnynZU3/qMpqOZ8ox2VS1Jk81MsXQn6N8BN04WrHApGodYIQlnr7ANi I+LA== X-Gm-Message-State: APjAAAUzRrLyxrqRgEPPL27jxq+OgMxHpD6QefcEgpJkbqUlydy/yg/r Gm3ehzpuKz7KNjp15osmYGSXXmdL X-Google-Smtp-Source: APXvYqyDKTbeQuvUKaZCqmtX0m+IudlJBTlBE1KtR84ApMpOXrdkFn2EciiAqUntKe/GdxgUBK7+0w== X-Received: by 2002:ac2:52b8:: with SMTP id r24mr1857926lfm.131.1567090091398; Thu, 29 Aug 2019 07:48:11 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id t16sm437836ljj.54.2019.08.29.07.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 07:48:10 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Viresh Kumar , Kevin Hilman , Thara Gopinath Subject: [PATCH 1/2] PM / Domains: Simplify genpd_lookup_dev() Date: Thu, 29 Aug 2019 16:48:05 +0200 Message-Id: <20190829144805.634-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 genpd_lookup_dev(), is a bit unnecessary heavy, as it walks the gpd_list to try to find a valid PM domain corresponding to the device's attached genpd. Instead of walking the gpd_list, let's use the fact that a genpd always has the ->runtime_suspend() callback assigned to the genpd_runtime_suspend() function. While changing this, let's take the opportunity to also rename genpd_lookup_dev(), into dev_to_genpd_safe() to better reflect its purpose. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) -- 2.17.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index b063bc41b0a9..27592b73061d 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -149,29 +149,24 @@ static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev, return ret; } +static int genpd_runtime_suspend(struct device *dev); + /* * Get the generic PM domain for a particular struct device. * This validates the struct device pointer, the PM domain pointer, - * and checks that the PM domain pointer is a real generic PM domain. + * and checks that the PM domain pointer is real generic PM domain. * Any failure results in NULL being returned. */ -static struct generic_pm_domain *genpd_lookup_dev(struct device *dev) +static struct generic_pm_domain *dev_to_genpd_safe(struct device *dev) { - struct generic_pm_domain *genpd = NULL, *gpd; - if (IS_ERR_OR_NULL(dev) || IS_ERR_OR_NULL(dev->pm_domain)) return NULL; - mutex_lock(&gpd_list_lock); - list_for_each_entry(gpd, &gpd_list, gpd_list_node) { - if (&gpd->domain == dev->pm_domain) { - genpd = gpd; - break; - } - } - mutex_unlock(&gpd_list_lock); + /* A genpd's always have its ->runtime_suspend() callback assigned. */ + if (dev->pm_domain->ops.runtime_suspend == genpd_runtime_suspend) + return pd_to_genpd(dev->pm_domain); - return genpd; + return NULL; } /* @@ -1610,7 +1605,7 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, */ int pm_genpd_remove_device(struct device *dev) { - struct generic_pm_domain *genpd = genpd_lookup_dev(dev); + struct generic_pm_domain *genpd = dev_to_genpd_safe(dev); if (!genpd) return -EINVAL; From patchwork Thu Aug 29 14:48:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 172630 Delivered-To: patches@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp2333938ily; Thu, 29 Aug 2019 07:48:19 -0700 (PDT) X-Received: by 2002:a2e:63cd:: with SMTP id s74mr5630965lje.3.1567090099609; Thu, 29 Aug 2019 07:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567090099; cv=none; d=google.com; s=arc-20160816; b=QVF3jK9hFjwRO3rxehqiUhEvlSxeYZRSlg2gAPIFvA2BuHvZZT84VnBYgXg1p3pH6H WAs38OaOnCK2cUenrTKdt8jS0QAiUmxz58stLOB+Y038z3xUfeCvP3LFJ2uhdDZ4X1pc qCHh0cYpaU27yjQTN/AQR6WEnDH93AagYpZSy8SGSKSrr0Ux3TQ13x0p8aY1mIhBaZyd VzEioeotgtLt2s0uu5GaC9XgFZRa/Ig7sNLW2eOVThqB+8xtF9fSQ3o8+gz0g0cKzr/n 5ogVsre12H4rsJ4Y3teonDhgo1anpsUcKULWGbQpP/Ymqt7G0QniNG7Vn341sHJuAazj /umA== 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; bh=KCuLpwKkgO2woISAKHKSXhqDDj9RTnVSFiBEmqI8qvc=; b=ONVk6rm9Tk7PNsi8XLec2CSCqk5YfeOZpjpETykVEmOvx1ba9p5UicRZcF72MfvqNC S9KCHY1qpCroeFlANWrfNDhUmQydQ1I0+AO2TL2wgQb3uJBlvyIvCUKtIxfkU09lgrSo 0j7U6RZNvv12oguhWKneqSm8ENsMkjLBrdiNGDXn55ol0vFlnWnCHtzaFQPgX4s20iGW MYvzlnmhAYFA8UUFDxmMO/gq/uPJx+4nTNKqit7Xg0AIX9uMXLxvU1Y7WdpR4nsXvEaU KH1QUPgJKu4h1qqMFHfOEo8y1FAikLuxEKNymlmT6nqLZJtqzB4qGPOitAeAYg/wOe3d t3mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IUCAvPjT; 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 h18sor1626519lja.8.2019.08.29.07.48.19 for (Google Transport Security); Thu, 29 Aug 2019 07:48:19 -0700 (PDT) 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=IUCAvPjT; 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=KCuLpwKkgO2woISAKHKSXhqDDj9RTnVSFiBEmqI8qvc=; b=IUCAvPjTBFoyU9PWJ2c/uU/nyvDbzYckQ6DEt4UvZg+TPRW+wVXsF5o+KwpT09SVbG CZHBf9LpzerenWeXgnRULTVrjizGumj5N8M7nQTd5UbJafylDSXX6vxlGL47gWk47gM5 hyOf0djwLpu6hMhe3xCWdMmDsR2P61YhXVyxfI0cMErFsklKsXOS70e+vGRaNMUg2wxe spAj+Pb5gpfyCYLUc5lbRAg4SwvPzqA+V241FNd3jqBVeqhnm5ec7YzvXekJDKuBkaZ/ xGHlbaObHBUxBpi0ybt9MjEfvktEER9BCzVLVcKcUaHk+USXen82UPG4oVQaJm9cyC5t sWOA== 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=KCuLpwKkgO2woISAKHKSXhqDDj9RTnVSFiBEmqI8qvc=; b=pJI/1AJXRF/TmpdwVpZHcdV9sNUuxVVKdkF/guqv0sS8ZYnkWjVIOU49C+3/43vYy5 w4tVvmkQF22M/dUn7NTRfJLwb03iJuFzt3c1iVtbYWyxBQmh9IA/1DoxUhI7K2t7lzu7 Rjx5aztjs3ulTlzx+ysscZ8n+qZvUtizpLfm+eMwB0i4vcmQg7EgLec/7yNStoaHwr19 srz7J8PJWvoyv27TmwffzMNRAKM/z7y3NpIBRlQu7ke0ty+yM4Rk3EFihT6HzjWe81n/ xB20gg5Fvpinc465KY8KdaLxujrNHcoZrVqu0CBitVpcET+i8m/ozjv6nUapFHkn17HV Z9Jw== X-Gm-Message-State: APjAAAWglKXtWG2AFV9qP7eYez4CfvK+ZKOI6sRwxHWQJ3X67+com+YG KOsflL9cc7iZugCL1Grc07CSaq2/ X-Google-Smtp-Source: APXvYqxnrAm5LDjdgQ6ZmgGYnHRwFhG95yl/IZaUiH1cnVVXHi49YcAQk26+ugMc5t8NW2tOLWMFrA== X-Received: by 2002:a2e:9a18:: with SMTP id o24mr5641521lji.235.1567090099148; Thu, 29 Aug 2019 07:48:19 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id r3sm385980ljb.96.2019.08.29.07.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 07:48:18 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Viresh Kumar , Kevin Hilman , Thara Gopinath Subject: [PATCH 2/2] PM / Domains: Verify PM domain type in dev_pm_genpd_set_performance_state() Date: Thu, 29 Aug 2019 16:48:15 +0200 Message-Id: <20190829144815.686-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 The dev_pm_genpd_set_performance_state() could in principle be called for a device that has a different PM domain type attached than a genpd. This would lead to a problem as dev_to_genpd() uses the container_of macro. Address this problem by using dev_to_genpd_safe() instead. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 27592b73061d..2650ae2f46fd 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -380,8 +380,8 @@ int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) unsigned int prev; int ret; - genpd = dev_to_genpd(dev); - if (IS_ERR(genpd)) + genpd = dev_to_genpd_safe(dev); + if (!genpd) return -ENODEV; if (unlikely(!genpd->set_performance_state))