From patchwork Tue May 22 11:34:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 136536 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501298lji; Tue, 22 May 2018 04:34:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoLPMoHUsgy2m8QR35TyrEiew3hapW7zJnm6U+fkWZI4ZiR8Ri+viIPb6QxHSqQ+QZYyOCm X-Received: by 2002:a65:4e03:: with SMTP id r3-v6mr19104181pgt.121.1526988866760; Tue, 22 May 2018 04:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988866; cv=none; d=google.com; s=arc-20160816; b=ZTNve6b7In2no00V10W8y85nnTooCIyYY5SqoYGL0c/CB1LSFCow0J4hDK0jMVED3I jwJvsNTlgKug2r6N9qha16GwTpw6fOsok9ar1gTVXRZ1PuGVWDsViu3qrWvTH9zrtlmv zhKloCo7zHVv1pxwRRV8t9KiWD2ndbqlF9Faj3wPv88FxWYjKhuKylHsxkb8va92Z4Qn Hm+KR28UE7bdjGIyvZYvcLm5ZzQqmBdVnJmphMgWO5kgwEsgkmfqCpjp/RD+AyROPB3g oNU2X3AfF2Rs34rQUrgwJV5xbl+lDsFACTbr7txFSObGwJkg3NnOk5KfmXC51BjaCqxs f7Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Pp08jTz6aT12v1/R1YgaZvRyRqHCjx/r+S+6v9bTkIs=; b=PaOnmYjt7cgbTSC0pFt3s6HS2KM8H3CCQ7BK7ti4B9RAPtLouoS46+hGrr6YVLJegB 01bHh504V+OAgBDWjbNMCkwqh9/KYkdyMuv4y4JzhODLnHPojmXR/PWTsNwrwRVz70zh WqpV9l4YlzBOpRm7Zk6kwF3GGtut0wPILq0+fA29rYXFNucWpKCHPsLuz/y6WbkoPPlX YvUugB7vRdhJpfLvRgCqv6XzUyJxgdCWqomVjpLO1xLkOgQQ/58fJtW0JrlQhBIH8sOi qi/QMNsg2DCoPFa4CdDqINL36a+8lZJuE6gYeIgfbVX4NpY2N5cqqT4tUrAFw5PhQBrU az6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G0rJCJ6q; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si16083025pfe.158.2018.05.22.04.34.26; Tue, 22 May 2018 04:34:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G0rJCJ6q; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752986AbeEVLeY (ORCPT + 10 others); Tue, 22 May 2018 07:34:24 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:40152 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752719AbeEVLeX (ORCPT ); Tue, 22 May 2018 07:34:23 -0400 Received: by mail-pg0-f65.google.com with SMTP id l2-v6so7749783pgc.7 for ; Tue, 22 May 2018 04:34:22 -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 :in-reply-to:references; bh=Pp08jTz6aT12v1/R1YgaZvRyRqHCjx/r+S+6v9bTkIs=; b=G0rJCJ6qNE5tIPqbeSpQKfGrZX88j0IXJTm9ajuIzglx3By0rRFR40QAnvQuwqUf35 Gy3qvHLtYz1pBx2Ju7fGHQS5yhdezr9AMyoD7n0c5tJrxNchHqoRrbO7i/BdSSXl9DGs y213bKMod8vjy3mEaXiPbb5fvQ89HXjMCKl3I= 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:in-reply-to:references; bh=Pp08jTz6aT12v1/R1YgaZvRyRqHCjx/r+S+6v9bTkIs=; b=EIll4yKqlUJ7N7PM07/Ri3lDojlU93FsRVqHkvseJxcma1GYL9zgpyUEuM6zE6B4AO Wc2Y/kvBFiZj1zlPAbDAsvCZxyRHsCnxicQlYjvTXwHCnFFXYuvxsPjUzztzIa4i59W5 D778e9lIyf3gMIY91dpMZALNs/n0m2kwjFVHpBG71LLl4zofsyk8ndGtGbKzCapqzfWM EHoYP5m4+iZc1HcQgKn4tNI945XS9TX2rCpDHBa2gdWnPOkNmeag++3lJxU7GZSBPKGG A5Gz8cLt2b+hTj66LeO1tkiRr43IzderGpg3oOntVYs8jFvpVuSzncLqqfKBYvHxavFB mU2g== X-Gm-Message-State: ALKqPwfrdzNelp4yanFvBZmG5yZfSSIwz4n+Qorxx7qDjvy4nSzGyyG0 ZV9O8SVBiUC7FlTI5VThOsm/RQ== X-Received: by 2002:a62:5610:: with SMTP id k16-v6mr23674080pfb.19.1526988862524; Tue, 22 May 2018 04:34:22 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id x84-v6sm38719430pfi.160.2018.05.22.04.34.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:22 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ilialin@codeaurora.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , amit.kucheria@linaro.org Subject: [PATCH 3/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_set_regulators() Date: Tue, 22 May 2018 17:04:08 +0530 Message-Id: <779b783cfaa726cbe35317ae2c1968c5496a3a03.1526988624.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org It should be fine to call dev_pm_opp_set_regulators() for all possible CPUs, even if some of them share the OPP table as the caller may not be aware of sharing policy. Lets increment the reference count of the OPP table and return its pointer. The caller need to call dev_pm_opp_put_regulators() the same number of times later on to drop all the references. To avoid adding another counter to count how many times dev_pm_opp_set_regulators() is called for the same OPP table, dev_pm_opp_put_regulators() frees the resources on the very first call made to it, assuming that the caller would be calling it sequentially for all the CPUs. We can revisit that if that assumption is broken in the future. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 86e8e2c1905f..780c89a49d18 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1320,11 +1320,9 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev, goto err; } - /* Already have regulators set */ - if (opp_table->regulators) { - ret = -EBUSY; - goto err; - } + /* Another CPU that shares the OPP table has set the regulators ? */ + if (opp_table->regulators) + return opp_table; opp_table->regulators = kmalloc_array(count, sizeof(*opp_table->regulators), @@ -1378,10 +1376,8 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table) { int i; - if (!opp_table->regulators) { - pr_err("%s: Doesn't have regulators set\n", __func__); - return; - } + if (!opp_table->regulators) + goto put_opp_table; /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); @@ -1395,6 +1391,7 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table) opp_table->regulators = NULL; opp_table->regulator_count = 0; +put_opp_table: dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);