From patchwork Thu Feb 28 13:59:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 10833121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76297188E for ; Thu, 28 Feb 2019 14:00:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64D5E2EEA2 for ; Thu, 28 Feb 2019 14:00:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5936D2EEAF; Thu, 28 Feb 2019 14:00:04 +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 000112EEB4 for ; Thu, 28 Feb 2019 14:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732128AbfB1OAD (ORCPT ); Thu, 28 Feb 2019 09:00:03 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:41264 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732481AbfB1N7f (ORCPT ); Thu, 28 Feb 2019 08:59:35 -0500 Received: by mail-lj1-f194.google.com with SMTP id z25so17199993ljk.8 for ; Thu, 28 Feb 2019 05:59:33 -0800 (PST) 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=tetivCWSellxrqLjg5oJkokMZQX4qsIXobIakEVk0Q0=; b=VNKVdDKp77nYxziG1tXDB+1+YC00/86ektZ137JuDXUybb+p7BQWP/4Nds+yqaWlib rDjw3j1RqlhfUzBaH0AhhEP3Oal0r0XwMCa89QOTJGA8qt68/R7WnvbQg23bXvoPHmA1 /+bIe0i+NlwTCQ1sv6umubGa15+P+2rAGbGXpMzM50QabTblZh6vh0GLMy2yhKPIinTK gvv1liY4PiqHQoOL24Lc50pUtriYV8B+8xRnBMe9TWpLa8IR32lR+o4JoTVyrb+DLU6P 45yDEaBHUzdwLkw7YMe5csbeq8sqZ1TXrTHoviYLSuzSWdtpnTLoVac9lYSgmfg65C0L p1lw== 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=tetivCWSellxrqLjg5oJkokMZQX4qsIXobIakEVk0Q0=; b=mihef0+ys/saQ7uBoYiHiEvai65FoNvCsWK8F1BVNtmr3fMwZ5XxNmaR4n0NuLDEbA 3+w80mJ6UYpVbgOFWKJj8kWwDoL4Iva+p+BLXEP5tM1NODIRwQo3Q+KbQWs3dxaHGjac bb6saWBkoXpZhPQky3pVizMSn10u1rVGYfPRpib70B0ZHlCCXb7dA6ynFdld1RJsf6x3 XII+CcaM1+6kJT+HkCHU5uuWRRL3IxAs2ADbxB+hNUkpUoVjNIUAjygvSj752cGo9t+0 7u2wgFxdFiRkC7feRu0qkPqTvN+LmgAfjT6cGLjKEdWjEDibM0Ld+HcL3YCJn+9S9EWZ gytA== X-Gm-Message-State: APjAAAVQ6ZSMjeTZjd2lyfHdPy3aBqp2mKvdoLn3kWYdQhsT6vQna2T0 L73stfJyXq2pXwyMoDn2KIlxag== X-Google-Smtp-Source: APXvYqx5P/Vqp+ogLd3hKLL4ats904OggXBtyJF+UQCD1hAYH52E0UWO5ytjMCr4hSE78iI1sOvulQ== X-Received: by 2002:a2e:2c0d:: with SMTP id s13mr5097543ljs.96.1551362372749; Thu, 28 Feb 2019 05:59:32 -0800 (PST) Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v20sm4090265ljv.83.2019.02.28.05.59.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 05:59:32 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland Cc: Daniel Lezcano , Lina Iyer , Ulf Hansson , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] drivers: firmware: psci: Simplify state node parsing Date: Thu, 28 Feb 2019 14:59:17 +0100 Message-Id: <20190228135919.3747-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228135919.3747-1-ulf.hansson@linaro.org> References: <20190228135919.3747-1-ulf.hansson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/firmware/psci/psci.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index d50b46a0528f..cbfc936d251c 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -290,26 +290,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); @@ -319,6 +313,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;