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: 136534 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501209lji; Tue, 22 May 2018 04:34:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqP7tEDIyffqakLNitum8ySeHvDfD5PDFr6AGkXkId6kSL/5uX8xPwn0Si262ZzyvfzT9Bh X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr23915523pla.287.1526988862154; Tue, 22 May 2018 04:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988862; cv=none; d=google.com; s=arc-20160816; b=ZqkOeLDyBk+0lE7sF87i1CYfOyki4thxZHYSFHPwtAQVbrghIq4Ibt+VHX+cN4FkyR 9VUxG7ScpI9Y0hn2kkK/XhAaVQCWzWTnvOkOnCOcJbcAPvRT5yGuWKgNDirdD+Re8CX/ IZWgHAeFiIgzOo+obn/Twr5a3NgwIr+Yno88t8LwteHPZ31Zsoe3WN8LbLlzt529wYMs MM1L0OUrMzYTUak4dp52ZW5NF9v4QeiB4tjPnVnRV/m5e0sVw0RkKD689pWgOar986pS NcpowCesv7/c7sBpop/V3OVfjH+i5y2rkqWVsoUdrvZ31GviZJf4RFCb8KmCiDXUDBmA VHDg== 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=9fhSEpFDhOfAXGpRd7GnA7gv001esXQhIOvd+5gtnbQ=; b=T2tsan0GfRqm7scBEIxRkjot+ZhIcCLI+6xvS9qQd3Msv4UiqwNChkcDgiPqtUwWzc ynKCibMSEX6Zbg22WMwgolIQitkUozBv9RNCuQr+Nguhkb10T+ZqDbQkjci65yqGe/gh ZU+WfJfIFkRttUoV7/gEAqMto7jKMRUysbeyJ1ZNDxvIUaY+6zLacGxU188QZZ4yQJP0 dazCWaOCxpD0T/2OpBerCT4z7VjxQVmV++GlNsp8mXE86Wbt5xuT2mOsQM2EaebV/ZCb PZZlKEUOFbG+StwXtw+om2uLSIpSqfmAMbrMZJPbbO0SLY9YzY+56Tz1HLYUStGK5lQj Xgvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nx8gTerE; 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.21; Tue, 22 May 2018 04:34:22 -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=Nx8gTerE; 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 S1751278AbeEVLeT (ORCPT + 10 others); 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-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 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(-) -- 2.15.0.194.g9af6a3dea062 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;