From patchwork Mon May 13 10:24:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 164013 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1137853ili; Mon, 13 May 2019 03:25:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSOx6A6djBCuvWed8WkbQjq6gbEuBQuwGb6rn0FibVGTMcSW/cgSRI30vi63WYkuEo7aoT X-Received: by 2002:a17:902:9048:: with SMTP id w8mr29068318plz.195.1557743151424; Mon, 13 May 2019 03:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743151; cv=none; d=google.com; s=arc-20160816; b=ZWvb+3ER4jeWEpQYpBCNaxtbntIY7wEvLvxhnaHFzD+9yFUlMp1b4tXSL6P5dXejok VIdcnnDuV8WFoytcwqe1wtzo4hxgSr01poU1ggJdD4EcU52zpVIGrNfWLNvPm7dKlK8E HcTSDPlV6hxc5DupVQBm9Szbpr83lrkYVdtip6h3Q9PIGdfz2WWmsmWGu7xuvRc+ioao KbmyVwnz8lbv+vQioAH/XF08A+qLBDkhB4SChKXGUZjC35cmqHTsrT3SSRqEVYrC+b6I xZkO6MKsorsczLnbVI6hw7w1j32IPYjQZkJhED2rTzBkAizpwTAepNxUDT4MenpVo7GD +VNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Cs4aUpEKLgkAcSCD22Xunu2gCyCIqjqZsKFA+jxsKFs=; b=smWvECDHODTlfq+WUlmZmAmmpA0Bc7e9jtDZzyZ2nUeAz+OqPg1ESzXJ6HvX9qYhqU S7sUufdOsaLipd3Kj4fq2Pc63hH/QRxoRwMz7UM5o9R0QiZg48BEw0frVL4BeWMulbhE TW569SHCoVncgF4aO5XvvQz4tsoxvOYgz15IBtCyQk8CIds9Oearuf1tnGMDFY6VzByr DSKhcdb5KAFojeQKj7MCIQiEDcjscJooX2k6ozj6C2TGoamcBGWQnNm8OH4OnzQm1NCS Y5SteFWMpqp1I+zyImjPeMZ1hqhXXF+HmHI8l4BE+knwxqEuGsFXXmKyRZ9g9SPfBAHu XhZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E6ocS6yg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 m73si15570361pga.271.2019.05.13.03.25.51; Mon, 13 May 2019 03:25:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=E6ocS6yg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727909AbfEMKZt (ORCPT + 30 others); Mon, 13 May 2019 06:25:49 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46774 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727758AbfEMKZs (ORCPT ); Mon, 13 May 2019 06:25:48 -0400 Received: by mail-pg1-f193.google.com with SMTP id t187so6533565pgb.13 for ; Mon, 13 May 2019 03:25:47 -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 :mime-version:content-transfer-encoding; bh=Cs4aUpEKLgkAcSCD22Xunu2gCyCIqjqZsKFA+jxsKFs=; b=E6ocS6ygS7TjcWC/tuQWZe961EteD5fozF5U2IzltzajiuzaGrAl/WYpQLDLnVnY+U RB57sfO59hNfQPNEtTKoyaPMQ09qdDd7et3LcQLqrsfxiJEnkoZh6bLriw+Fa429kfW+ Bj2LA/6jXXR4vcXuvP7HK5cNpXmPm4sTz9lnyT39q06YBRzmyiAFjqIK9tPxC+3Ngumr ltBJxwtQkucUsL00OsYT4kOEARRYCA28M3W6BuTUAzJ7O+zvsH629DV5UAxqcRqBkx/X 66eWmxQJG3DLaud5TjbhXlZkwfV+biYQtpaK6I98+8E4Lqculi7X4A48ziAVspAA6OEX 2OSA== 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:mime-version:content-transfer-encoding; bh=Cs4aUpEKLgkAcSCD22Xunu2gCyCIqjqZsKFA+jxsKFs=; b=TcA7Mr1JoAhnYU6zfr1Cg9yo9WJHpzR9jzfMveRe9RunLX6jv5l6FsS6SI+42FmcqZ oS4GC8kp39SSS28DiLQRFlQUNEihuZf9sGxbmtVlb0F2uH3JJyzHPT4yhP3npOFuMtc8 0/vdQovouZHVgO9rNXcRMWFNZ0z7rB9hqQvc1KqFzDBTAmIEYGU8bln2MQnkpOa2wj+n RzVtgoygOTvF8UJNpvhZmuWjHY1kY+l0RfoKGlYgph1v7fVsuJGKeu+/MuQ1n5eHajYo ACTcsnitVUCZZ0YcG/MOntgs710W6Eb37pKBxivrK+he01IpW8cNb6ZWUx1CRrmei5MZ QiAw== X-Gm-Message-State: APjAAAW/z4/s7OHDbc9uu1H1TnhjSM+nBZs285NqWCNPoeBS9nwsBT4I pKkvi3Wlq4iBg9UdbUSgJXlKXg== X-Received: by 2002:a65:56c5:: with SMTP id w5mr30123588pgs.434.1557743147101; Mon, 13 May 2019 03:25:47 -0700 (PDT) Received: from localhost ([122.172.118.99]) by smtp.gmail.com with ESMTPSA id s5sm3927132pgj.60.2019.05.13.03.25.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 03:25:46 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Amit Kucheria , Rajendra Nayak , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] opp: Allocate genpd_virt_devs from dev_pm_opp_attach_genpd() Date: Mon, 13 May 2019 15:54:11 +0530 Message-Id: <9f22d5954319fc315bc98e347e69839931648ecc.1557742920.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: <1bc9053f5c41a10832b58a2a81decbad7f1aded9.1557742920.git.viresh.kumar@linaro.org> References: <1bc9053f5c41a10832b58a2a81decbad7f1aded9.1557742920.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the space for the array of virtual devices is allocated along with the OPP table, but that isn't going to work well from now onwards. For single power domain case, a driver can either use the original device structure for setting the performance state (if genpd attached with dev_pm_domain_attach()) or use the virtual device structure (if genpd attached with dev_pm_domain_attach_by_name(), which returns the virtual device) and so we can't know in advance if we are going to need genpd_virt_devs array or not. Lets delay the allocation a bit and do it along with dev_pm_opp_attach_genpd() rather. The deallocation is done from dev_pm_opp_detach_genpd(). Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 10 ++++++++++ drivers/opp/of.c | 30 ++---------------------------- 2 files changed, 12 insertions(+), 28 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b Tested-by: Niklas Cassel diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 67d6b0caeab1..764e05a2fa66 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1755,6 +1755,9 @@ static void _opp_detach_genpd(struct opp_table *opp_table) dev_pm_domain_detach(opp_table->genpd_virt_devs[index], false); opp_table->genpd_virt_devs[index] = NULL; } + + kfree(opp_table->genpd_virt_devs); + opp_table->genpd_virt_devs = NULL; } /** @@ -1798,6 +1801,12 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names mutex_lock(&opp_table->genpd_virt_dev_lock); + opp_table->genpd_virt_devs = kcalloc(opp_table->required_opp_count, + sizeof(*opp_table->genpd_virt_devs), + GFP_KERNEL); + if (!opp_table->genpd_virt_devs) + goto unlock; + while (*name) { index = of_property_match_string(dev->of_node, "power-domain-names", *name); @@ -1836,6 +1845,7 @@ struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names err: _opp_detach_genpd(opp_table); +unlock: mutex_unlock(&opp_table->genpd_virt_dev_lock); put_table: diff --git a/drivers/opp/of.c b/drivers/opp/of.c index c10c782d15aa..a637f30552a3 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -141,7 +141,6 @@ static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np) static void _opp_table_free_required_tables(struct opp_table *opp_table) { struct opp_table **required_opp_tables = opp_table->required_opp_tables; - struct device **genpd_virt_devs = opp_table->genpd_virt_devs; int i; if (!required_opp_tables) @@ -155,10 +154,8 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table) } kfree(required_opp_tables); - kfree(genpd_virt_devs); opp_table->required_opp_count = 0; - opp_table->genpd_virt_devs = NULL; opp_table->required_opp_tables = NULL; } @@ -171,9 +168,8 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, struct device_node *opp_np) { struct opp_table **required_opp_tables; - struct device **genpd_virt_devs = NULL; struct device_node *required_np, *np; - int count, count_pd, i; + int count, i; /* Traversing the first OPP node is all we need */ np = of_get_next_available_child(opp_np, NULL); @@ -186,33 +182,11 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, if (!count) goto put_np; - /* - * Check the number of power-domains to know if we need to deal - * with virtual devices. In some cases we have devices with multiple - * power domains but with only one of them being scalable, hence - * 'count' could be 1, but we still have to deal with multiple genpds - * and virtual devices. - */ - count_pd = of_count_phandle_with_args(dev->of_node, "power-domains", - "#power-domain-cells"); - if (!count_pd) - goto put_np; - - if (count_pd > 1) { - genpd_virt_devs = kcalloc(count, sizeof(*genpd_virt_devs), - GFP_KERNEL); - if (!genpd_virt_devs) - goto put_np; - } - required_opp_tables = kcalloc(count, sizeof(*required_opp_tables), GFP_KERNEL); - if (!required_opp_tables) { - kfree(genpd_virt_devs); + if (!required_opp_tables) goto put_np; - } - opp_table->genpd_virt_devs = genpd_virt_devs; opp_table->required_opp_tables = required_opp_tables; opp_table->required_opp_count = count;