From patchwork Mon May 13 19:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 164054 Delivered-To: patches@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1728274ili; Mon, 13 May 2019 12:23:15 -0700 (PDT) X-Received: by 2002:a2e:4a09:: with SMTP id x9mr12731350lja.19.1557775395479; Mon, 13 May 2019 12:23:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557775395; cv=none; d=google.com; s=arc-20160816; b=Dz79tfAQOGgbABqYC8CoYgHYT8KWQ+L+ZGRdnoHggzDbhKcMz1Rtj58vXE/lBMFT12 3Nk+zBRpDuMoI99mDurXBFqU/neq+DBBmMTSQSXUCuya7yWca9uNDFI1krBjCi0u0pOW jmWBDlAvz77gPVLD0OLvAKESyOj0vNW33YwakSL0z4BVDLT08nhupG1HmNWlGdEF54cx hvJDUSMsuH0Tn/IISL5/p53vmrhvDBicL7zyW6LVYADvRjKgZe2Blq3pM6lc+sbvbrnY gtseC7xlyr2c9VNIFmXcpkMlDPgZEd55+f8dbtEeoQ26qiAuey1g185Cu5y+jA5Z/KkC Npbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h+mBrphGE8r6kKGvHPN2hwwjlulIBItsLgwHs6HK8tw=; b=hsv21B83xhh9xJM8kUsgVWJ0WOZr5eTxcJk9ct4tGDoxze7tkeuPQY2c8yIS+MW6bP /deen3xzFnJaX6vZeSdSIILrxCZLHLjEB7vZW9gIh4cI3CRsDs6xN7mRotkiG3UiGwUo N0bf/tJG4f6KYGLHs5s6ySTGlzGpiI3MMtIvwWyNDx0qAUG5fbicqC5CWtcHEyRTkEfq AtEE2kWpSNZGSNNt7ag+CLad+D4xA4BYAsC0rB+XduTt8TCnbcfdH1G7d6cBcbJrD4lh j6Z0zRPI8jrbijLrdMjTylun1Z7l70QMku7VDPdZg1UUDknR+yvdnMhcJejiwgsO2bdB 0peQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1qwoOxf; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p16sor1392428ljc.9.2019.05.13.12.23.15 for (Google Transport Security); Mon, 13 May 2019 12:23:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1qwoOxf; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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; bh=h+mBrphGE8r6kKGvHPN2hwwjlulIBItsLgwHs6HK8tw=; b=z1qwoOxfxP8ws6K0eXeqsi0M8rg4AiA8aC+/rjIVQbuJPoKSAquEg4iySw4L3cN5x8 jjlTDZuSJciHj+R09dPL+gALzrtUwcXOVPCSnr1zV5JjUxXC+jTH/bs1uFkycg9wYG8L 3ilSYwaJ4Q/40soKA1mrFGCJYk6E1a5pkxpihVokTsS7TPrP5nTxTdm7Jw+QAnCFWTxO uSmb50ZRpi0pFqGue364kuAdvMUhtO582nHQ8c2OptpkJde/IrOfk1AUVO3SIIewRV7N vt3h/dJVN+5qmhzobmOPYqBY1Id026c5O41E9qZf/leKI1FYytDGLpKNJm1MNCm4XpMm 8yxg== 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; bh=h+mBrphGE8r6kKGvHPN2hwwjlulIBItsLgwHs6HK8tw=; b=SIgZbpno9uEMokenP6aEzRP0Uj1daWiMqY/AKsqvDdY3JYMRKnQXG8rEuCf2Uh2Ejt m3Buc+A2Ja6oatPj/vGlfreB1QChaS+mw504pLIMkgUbv4SNpYC8W1E7PVCImnxRk5Xt 7W1JeteIhfEJQw4DH3iRYG+Np5O+CQ+LHvkLyfd8C+8v1GFJryhw/EI9Nk08exLNu9+N WbfBo/rypR6gIz6oyEK18sbegLZ67V1Pp2SgyyyjBIwM6qTIf4M/EyinzLqDXO8Selqw KlmoNRIuIfJ3nUO12ZdMyoZ5cPpPwmLRW4iO8hwxMP8ovMJQ3sB/ydPhDKggzvcY/xnp t71A== X-Gm-Message-State: APjAAAVhBz99f87ESsahkiBnyHFpjLApGd4izykDWX/HPWtthFvjSiQx t2BV39QruxWbIUefAKfVYHzEBx9H X-Google-Smtp-Source: APXvYqyeVfJKdGokU/doivXzmlRxtYYG8D4KXKrSzXVVKA9wCQvIkwAm3xVkfpldRQZcHwdKpXbyIA== X-Received: by 2002:a2e:9241:: with SMTP id v1mr14737256ljg.6.1557775395160; Mon, 13 May 2019 12:23:15 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id q21sm3449365lfa.84.2019.05.13.12.23.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2019 12:23:14 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , "Raju P . L . S . S . S . N" , Amit Kucheria , Bjorn Andersson , Stephen Boyd , Niklas Cassel , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , Souvik Chakravarty , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Ulf Hansson Subject: [PATCH 05/18] drivers: firmware: psci: Simplify state node parsing Date: Mon, 13 May 2019 21:22:47 +0200 Message-Id: <20190513192300.653-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190513192300.653-1-ulf.hansson@linaro.org> References: <20190513192300.653-1-ulf.hansson@linaro.org> Instead of iterating through all the state nodes in DT, to find out how many states that needs to be allocated, let's use the number already known by the cpuidle driver. In this way we can drop the iteration altogether. Signed-off-by: Ulf Hansson Acked-by: Daniel Lezcano --- Changes: - None. --- drivers/firmware/psci/psci.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 88e90e0f06b9..9c2180bcee4c 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -306,26 +306,20 @@ static int psci_dt_parse_state_node(struct device_node *np, u32 *state) static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, struct device_node *cpu_node, int cpu) { - int i, ret = 0, count = 0; + int i, ret = 0, num_state_nodes = drv->state_count - 1; u32 *psci_states; struct device_node *state_node; - /* Count idle states */ - while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - count))) { - count++; - of_node_put(state_node); - } - - if (!count) - return -ENODEV; - - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + psci_states = kcalloc(num_state_nodes, sizeof(*psci_states), + GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 0; i < count; i++) { + for (i = 0; i < num_state_nodes; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -335,6 +329,11 @@ static int psci_dt_cpu_init_idle(struct cpuidle_driver *drv, pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } + if (i != num_state_nodes) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0;