Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5554314yba; Mon, 13 May 2019 12:55:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjWj+PHFXZlybUEaVA97nQ3Mrj35E9PHwPI5mlkexEAGXTfYCxWcqz3gKqqIcPcoE2sZqP X-Received: by 2002:a17:902:8f8d:: with SMTP id z13mr26972914plo.166.1557777335934; Mon, 13 May 2019 12:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557777335; cv=none; d=google.com; s=arc-20160816; b=q8tHD5o+LYhR7z2iBWj+qDSuOoTew3NbAxzQEc5pIobXrjkNcV5heNLJxhX0TUrGGP TvSextMoF+lgXIkicdcY9cGCSsciExlfqJQSuETqAs3crmS5oMVx8IAqkHbw8xmB5I9s SgiGK9lQrHVpnkgywB9ZP76xN9vvhUiZQN+g+1lXDOq4iBHf7nR5zMcFkanFVKgzto9X SZZxniWxtoT8pYYM/eB8X+Xg4gyMP2MsIJwQ58om70krG6w4XXn20NCz7+KJRv3CVvB+ 6AMEAv+mKpySAkzFHGz1p1ySUGpwbNsLOqA0Cw1IfH1mUCPUSm5f8o9jIMot8Ulu4/Rv DjJA== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=h+mBrphGE8r6kKGvHPN2hwwjlulIBItsLgwHs6HK8tw=; b=IkkQKJuOjtFCtLmoaxe4wPMNKryKrwjCA9meFzRG8aoBTG4v8IwmU4ob8s9yQbZcOW XyXXs/8f9PQ7GcPFVrBqkNvSUau58l7THWvsOE076RCjCtOF+1JpojZ/7Z6AxgygQVcS iaWM1W2uBOBJh3PMdUmHCBBkExYWV23ngbpiqrnNEhLFdRuIsgvZcDOjYLdu59EmmAFc rCA8P9b9PAo4Lc9WjFFl5VzFtL8yP0Mi8HKP1zEFoT+jBmhO/PYG0tO8JMSjWFpejgw2 A6lz9G2A2I4aeqL37h+QmRJ9YvUSt7hr0yOa1EyF6Ceo+aklE+SUBsE2nf8FLXfR973K x58Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z1qwoOxf; 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 e123si3925488pgc.24.2019.05.13.12.55.19; Mon, 13 May 2019 12:55:35 -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=z1qwoOxf; 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 S1726501AbfEMTZN (ORCPT + 99 others); Mon, 13 May 2019 15:25:13 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:38901 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729598AbfEMTXQ (ORCPT ); Mon, 13 May 2019 15:23:16 -0400 Received: by mail-lj1-f194.google.com with SMTP id 14so12078189ljj.5 for ; Mon, 13 May 2019 12:23:15 -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; 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=ew/X4cPFhersqE1O8M+rxkWhwNWP0i23h2MyVyfrqDmQkCcJrT5y7KQLex6Bc6liwU lTMGW/w5Gdb0TWtnwgZi9ZD3VsLmt5x9QKdGAFQkpE5DdpCI3lXCSL5sDnDuFj8+CMRT L/D80Liq4nsxbwkph7wU0540yvAHaslV9QWXZHkglFMvgE5uTorGEn8uO0XYhP4+ViUo uLPL05iB9DGnRJbuWfCKZ93Nt6jPgaSGsJAlk230YHZEeRSkpQh05Iyt3E5F5fsmJvrG +zsMo0FBEH6c54fWii0+1CKuVO988fyZfyocd59pht/ixWDKrt9fF7NvmMOyAVbX8sdP u9Kw== X-Gm-Message-State: APjAAAWJLoNd27xyMlB2iAgPlbREwN4pJuUSXzomTgbZviCMuFoE/ILA ysmQhCYxZ6fs5zGdI80mleq9ZQ== X-Received: by 2002:a2e:9241:: with SMTP id v1mr14737256ljg.6.1557775395160; Mon, 13 May 2019 12:23:15 -0700 (PDT) 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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(-) 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; -- 2.17.1