From patchwork Tue May 22 11:34:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 136535 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501273lji; Tue, 22 May 2018 04:34:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpxyV8059ov65RN6e7lMv9HNSmSyF/aITKgDW8XhAhS9V4W6ZUHCecHZD+SElwx9n/mEDwq X-Received: by 2002:a17:902:1004:: with SMTP id b4-v6mr23915858pla.82.1526988865557; Tue, 22 May 2018 04:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988865; cv=none; d=google.com; s=arc-20160816; b=hS1dypMkvJx+OrT/At6u8sivtYLhdVWCJhxNeGgar7AUebPlGQIL5CqvcbJkS9D+9+ fTSkjHUSX7O0lSu19SBNtq4X15E66FOUUgUDVV6FI/KQym5yBIdatrS0dHuE3j3WbFxw TFpWoowmZFiSR3dDg8icQ03SCJiodG83i5VIPpHjvyG5rBpeTljVlPk/ItrddZZLioo8 H4QFTJ6dG4tBT7QQWOS5U9VBNVGuGtwfF9Eim1K+wbDaUuPZU/eoppf0xDMjHk+dwiyR l8zJuVuke7+M5KwD9wf0CdGhtTZqJbeNjxitO/VY+hx8ImjFL3aucfgyQrQnHo0yR3Ax 9/iQ== 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=5T8/cv5o59a28hEbzUm0/3ssnG/cGhlzW/1AMUv0uHo=; b=BPgJdkGRi0LuLLyd1R/MYhMKLSptvU+abKhcE9ah1XgPr+emhh0rSf2sP4/+LLCKCC Nstr/WUlfO79qAKNoG2apBKvaEJLjEE/hEiYarfGXfV6D0ysBAKLiwplk4N+yCaKfH1R xN6DnBS/FNZo3HymDeyB1ZcG7McpcIK5DqBsjBgfZV4pXhoOm5VSkxwi8H+FxeWx09P4 z1CDXhu0+qSi8ZK779vurtuHXfKeUe58ZWwAb4FqJwcLr+t0ywtHpAGzhZ7VanmQcBal cBLoeg1uGCqPjDzNhIjyZ5/rS/TihoRVUrJWRhlSZpeMfTzHdvlGKGvNOJCRw0DKZ0Ex 7fBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aUuoSnQF; 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.25; Tue, 22 May 2018 04:34:25 -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=aUuoSnQF; 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 S1752994AbeEVLeX (ORCPT + 10 others); Tue, 22 May 2018 07:34:23 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:44032 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752986AbeEVLeT (ORCPT ); Tue, 22 May 2018 07:34:19 -0400 Received: by mail-pf0-f196.google.com with SMTP id q22-v6so8633380pff.11 for ; Tue, 22 May 2018 04:34:19 -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=5T8/cv5o59a28hEbzUm0/3ssnG/cGhlzW/1AMUv0uHo=; b=aUuoSnQFuQfB2SIrE4xjgJy4iy6E3i5amWrjGx4mbx13nrUg8uNG5eao+Nt6MS/HdO ykP1MOyHls7fXZHqGzKj+pbX8p5MJHTcP9nrUXzQyybxKp3lUGa3Tq1AmMzIg2oCBRUI GjBqkubGUnF1inZUTrxi9KxkmgWFqwxQguvEw= 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=5T8/cv5o59a28hEbzUm0/3ssnG/cGhlzW/1AMUv0uHo=; b=W/niplJwtNwKV4PIUBERNYcN76wFAAgguOsc4usiTTmtk0bn5NxqwlBOtHJQedFvGX vXha8WEfCkcgRTdb3zP3x+po8lGS2/jC1IYsdwEp8rT4lWQB2pTahqXSRStkxno212Gx YI7x2LKPoyaTArEqYGE4AqznEuJKYkGz4BB4xrWUk5AHVwaU6WAJgP8zeN682BRsb0Xm xTeRpCKUTdTLsjTF2dnhicUN4iI/cxsq6lWseJK/vAAsxxiz71a92b6jW2HrImXV7/rJ tvHN61ZdCE7IJTFPhR1XTvlM/2EbvoIhv9TMMwk4nAKuv68jZdqVvLMU+W8lc/8ORSd3 8ViQ== X-Gm-Message-State: ALKqPwcrW4RSAYyQXN1yt2NZgb81llfdmZ8E/EzBdADO+jVm39mFPipU PFileZPkHNWewpoMUyufDYrpqj2gLjc= X-Received: by 2002:a62:7105:: with SMTP id m5-v6mr23275556pfc.167.1526988859296; Tue, 22 May 2018 04:34:19 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id w134-v6sm27796468pfd.187.2018.05.22.04.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:18 -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 2/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_set_prop_name() Date: Tue, 22 May 2018 17:04:07 +0530 Message-Id: <878ec1a9f0e5a6b344c12fdc349ec7cb036c2a42.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_prop_name() 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_prop_name() 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_prop_name() is called for the same OPP table, dev_pm_opp_put_prop_name() 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 | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 481affb783f3..86e8e2c1905f 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1216,7 +1216,6 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) { struct opp_table *opp_table; - int ret; opp_table = dev_pm_opp_get_opp_table(dev); if (!opp_table) @@ -1225,26 +1224,17 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - /* Do we already have a prop-name associated with opp_table? */ - if (opp_table->prop_name) { - dev_err(dev, "%s: Already have prop-name %s\n", __func__, - opp_table->prop_name); - ret = -EBUSY; - goto err; - } + /* Another CPU that shares the OPP table has set the property ? */ + if (opp_table->prop_name) + return opp_table; opp_table->prop_name = kstrdup(name, GFP_KERNEL); if (!opp_table->prop_name) { - ret = -ENOMEM; - goto err; + dev_pm_opp_put_opp_table(opp_table); + return ERR_PTR(-ENOMEM); } return opp_table; - -err: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); @@ -1261,11 +1251,6 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table) /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - if (!opp_table->prop_name) { - pr_err("%s: Doesn't have a prop-name\n", __func__); - return; - } - kfree(opp_table->prop_name); opp_table->prop_name = NULL;