From patchwork Thu Nov 29 17:46:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 152437 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2672312ljp; Thu, 29 Nov 2018 09:47:29 -0800 (PST) X-Received: by 2002:a19:2b54:: with SMTP id r81mr1727361lfr.34.1543513649907; Thu, 29 Nov 2018 09:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543513649; cv=none; d=google.com; s=arc-20160816; b=lj5x7xfHgAdkMdFSjueHavXTYeEodoHONHpCmYjSfcpylJtm6lDqBVLtbWj7vHWK54 T7FVRcPGXMihDnw9DD1PAHRu59n2Fg02CfRB8499oD5dwpFZOrF4M18jicYOJ0Cw1uXo ZqZ3oS6GUwaBXUzNS583gStt2XHfq1S7v2PzQJcM1tmQSYVcW5DyEhT+UQhQEVj4okVK 6FMxB1S+O3jOZZCVdve13kT06zT6SIouJld+SYa2sGO9k4sIx2DLJf/3O7vkV3u2HPLX vFQj9se7cetnUXh7ld5xz8VZTBbkvUIS3eg+GeKEeUHQWHU263hi+EzlRjTzeeoNv7rM Vvyg== 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=ZnU2zg5+wIbWo5O0mmqI6742JstHQYNw0KGOcLMkauw=; b=ya0p+wghaca003mnx3csol6CF4kZPILiAKaaelpcKzdrQdY20RUifVisFsJc6cw9QZ d1Glfu1Y6ZH1J+PuJcsEWmzUY9BBpZVzEp4No9cDJUTRjV+FxFao3Wv/RMM6d9EeUnWG avI+DVG6XZ1ywWxaEkoL0HpZMCt6LaedhCS5SToydllDCqou0mwu+BoBVSBa8ogGCMoY UlgtQNemRhDWSC2G+3ZVmYwBXgXSfbHY0Y5jvOGUImE1ZYd8cgRHQB7txMPAl9vC9aM2 AarEOZKrMoMfos6VqxjVRqwtFpUU6LfcgQRufQmvfhb+oea8HyM69NxITTMaW2CqsUJP fAIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gc/mEof6"; 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 o194sor777305lfa.64.2018.11.29.09.47.29 for (Google Transport Security); Thu, 29 Nov 2018 09:47:29 -0800 (PST) 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="gc/mEof6"; 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=ZnU2zg5+wIbWo5O0mmqI6742JstHQYNw0KGOcLMkauw=; b=gc/mEof6FAHJILmhbUnZDwxeH3clqii9e4boH+PzYfTjHTpHvntzwcHeA4X/TZUQCO nEaYBT3n60JTTzq82pT8Jx8y3Ni2mBBoG8mGM8FR0XlTfs3oYJZ8Icwa0KV7QnJ8zC0z 1x2yIJkBRlAHnoX+Xfz8x50/nIvF5nR+udY6k= 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=ZnU2zg5+wIbWo5O0mmqI6742JstHQYNw0KGOcLMkauw=; b=CEniNRCsqZTYYENf4L+iEIjUnEekD9lHTy0uIMyr9ans2Roa+uuroggXQ8oBhep2Hn T+0342+z/MHAz/0ZO9yL2tM3p3tGH+i0Auhtsai27RG3DYH/0dy4MdGgyjJ1D0jJ0NdQ HB8dr+lgR53UDpHZjOgNHe7N3EIN32UDJ1dpx8hRjW6fWAV50+YjlK8K6TxkRUAkueja 2sVc0sQTWWFyxrXPJIEv+yoQ6b75rDV6jfplKQfz2d4U3ZKLkaHe1PYHOLY3VcXKaLGF m/4qRjZj/OyMxMgHu3K5WAzeTu5G74zVGZ6uCXGSixeVAAcLccTtrbI6A8nhdrx4tWmo SB2g== X-Gm-Message-State: AA+aEWYGnAkGh0CdOOEXqbxErn1kD5mtLw7Vk5tVEnIzk3z7kUGKThnT vhKNpWNWGLb7WemNMfuNxZwfNs/d X-Google-Smtp-Source: AFSGD/UfhHk4UsCzPn/eAc1UCLzaQXf6ETh/uaMawQcc+6G7rBPGahcf/FhFDVQ7YPe4Sfkg3pEBVQ== X-Received: by 2002:a19:a84e:: with SMTP id r75mr1697958lfe.45.1543513649619; Thu, 29 Nov 2018 09:47:29 -0800 (PST) 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 j76-v6sm393983ljb.12.2018.11.29.09.47.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 09:47:29 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , linux-pm@vger.kernel.org Cc: "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v10 12/27] drivers: firmware: psci: Simplify state node parsing Date: Thu, 29 Nov 2018 18:46:45 +0100 Message-Id: <20181129174700.16585-13-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181129174700.16585-1-ulf.hansson@linaro.org> References: <20181129174700.16585-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 --- Changes in v10: - New patch. --- 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 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;