From patchwork Tue May 22 11:34:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10418139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6CEC26016C for ; Tue, 22 May 2018 11:34:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E58E28C09 for ; Tue, 22 May 2018 11:34:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 531E428C15; Tue, 22 May 2018 11:34:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E821728C09 for ; Tue, 22 May 2018 11:34:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751278AbeEVLeT (ORCPT ); Tue, 22 May 2018 07:34:19 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:38156 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752993AbeEVLeQ (ORCPT ); Tue, 22 May 2018 07:34:16 -0400 Received: by mail-pl0-f65.google.com with SMTP id c11-v6so10750436plr.5 for ; Tue, 22 May 2018 04:34:16 -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=9fhSEpFDhOfAXGpRd7GnA7gv001esXQhIOvd+5gtnbQ=; b=Nx8gTerEntlpJkwB8uJXRLau+8wL9DSWyeQutyBkF9c1UWxGLfZpBoKraWJNO9bDyH J6+o/yfDMMTmDH/S+ZsT4FxzKJN/9w8RL+ZiJeZW16uFeRBQNqjGfBYLBhde2Exv2lxj OT89ChevbnyF5xkCUkGvBmp4j8VCIFabUo2MI= 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=9fhSEpFDhOfAXGpRd7GnA7gv001esXQhIOvd+5gtnbQ=; b=PQwfN/lGgg7kMhCz+s6X3QjJ+aAowOKeeAQ8Xs48JfiIBhNQbcFc49zele0Gc9Zrpz Vfag30yaCXltX9fD/wDc2AoXx8N/ANpxu6Euv/fINWH2CtW4YQvwE9mbs1SnpgXHSiVE SsganyIQudZt9ju5T9PJz+4M0Xg9IcratX4Tp/sFbh+MBm/m35nKVm0JDT1LY8mAnk54 rVD52Hw2oTBzVBYUZgLFSxEwSuSeFJXHVZyA0jt3i20iBgR33RgNA5cwKDKWm5bwvcNJ anJ0BCFI7YgE3QtGfcO1N0WQh7isqP06PVZ6p4uqZnJiHsn64PKO0TWzUrMKMfZh8q+X sR+w== X-Gm-Message-State: ALKqPwfw3t+U+7eWIGT4QgkilBQepFJM6WJ8FDUpF7/8CQRfaBQo730F aHea56TY8R61UqW9PbuqU9xfjf2jxuU= X-Google-Smtp-Source: AB8JxZrI/tz1LxVUCOiJhazy/KGnG0Bbuhe8PhxhkXZNw4o1iwTgaD79a4eWizAEg8Fldjlh1RSS9A== X-Received: by 2002:a17:902:bc4a:: with SMTP id t10-v6mr24334312plz.343.1526988856191; Tue, 22 May 2018 04:34:16 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id m14-v6sm25595506pgs.72.2018.05.22.04.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:15 -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 1/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_set_supported_hw() Date: Tue, 22 May 2018 17:04:06 +0530 Message-Id: <25419de1b8dda24f3e02478b12b724a9b0cc4e78.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 X-Virus-Scanned: ClamAV using ClamSMTP It should be fine to call dev_pm_opp_set_supported_hw() 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_supported_hw() 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_supported_hw() is called for the same OPP table, dev_pm_opp_put_supported_hw() 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 | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 6d3624ba89b6..481affb783f3 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1157,7 +1157,6 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count) { struct opp_table *opp_table; - int ret; opp_table = dev_pm_opp_get_opp_table(dev); if (!opp_table) @@ -1166,29 +1165,20 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - /* Do we already have a version hierarchy associated with opp_table? */ - if (opp_table->supported_hw) { - dev_err(dev, "%s: Already have supported hardware list\n", - __func__); - ret = -EBUSY; - goto err; - } + /* Another CPU that shares the OPP table has set the property ? */ + if (opp_table->supported_hw) + return opp_table; opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), GFP_KERNEL); if (!opp_table->supported_hw) { - ret = -ENOMEM; - goto err; + dev_pm_opp_put_opp_table(opp_table); + return ERR_PTR(-ENOMEM); } opp_table->supported_hw_count = count; return opp_table; - -err: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); @@ -1205,12 +1195,6 @@ void dev_pm_opp_put_supported_hw(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->supported_hw) { - pr_err("%s: Doesn't have supported hardware list\n", - __func__); - return; - } - kfree(opp_table->supported_hw); opp_table->supported_hw = NULL; opp_table->supported_hw_count = 0;