From patchwork Thu Oct 10 11:39:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 175757 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2163093ill; Thu, 10 Oct 2019 04:41:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4d4liC8XQ0x0pUAD5vJ28+S1RpcgfjnKC7CXvbyhHh39a42CgLwbqtUPmf2lH2YXzgcaO X-Received: by 2002:aa7:df86:: with SMTP id b6mr7595989edy.107.1570707619622; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570707619; cv=none; d=google.com; s=arc-20160816; b=gqqwYE3w20JoCcNM6ZlVxxYFHhxV8gyiWmxnjZiVBL0tOhN8ewpaMv+8niL15gMZaR C0Zwi0pJbrINl4d3/ID+8OnL9wo6msCnyabx9AyTVLRdpS+9FABC5p0xcfYHUjwooBd6 jrRwovMj9Z+EzocyajuGNSE0aJG4KjzUTxZr8JaLALPorfqh7gJGZpC93mWk3XiQF+bG 3cczuituKXzcb1D/KUH9xAZSvaLglCu4MoA3mCCqNgOEYuuh2SVk9x7DbmyaKH3NK9RF AvkjOnBhTdQA4yNnBa6voqZWK44IRimKG/TnOV+eW1kSLN060QorTGjfboi/4Tu/wjpT 7Ocg== 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=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=ferRzGdOQ81RhJ8JYe8eHCY/uZsagndf/mBJSw74io2lN1UR57SY2RniznRryl02Fo z++L7SdPWW/ajAWq5jt326aK8gQpxJQwddsOqxrBxvYcdfyU2GJjeE6wmi0uC8nqsg5s 6qfUWvtJ20hIzaefpudNN5+AlcuMMTkbdMhNV5NHnQikwk9e04YqjNjel0nHaPMnkomr gMwJG/+CFn5llp+J9XiSeXanTil90kt0AkLqS7RUByfXhTtaEHeyhfcPTYzZv8rs7t3R /d+zIoxr23Fn8qQbKOuP7ur1gZFtfTq2XdURGLEtUzKF7eEAdBflKdXXOHpkXkp9G4HD 1AFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/wpfkf4"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 c60si3016856edd.327.2019.10.10.04.40.19; Thu, 10 Oct 2019 04:40:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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="w/wpfkf4"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1732838AbfJJLkS (ORCPT + 10 others); Thu, 10 Oct 2019 07:40:18 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39677 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728912AbfJJLkS (ORCPT ); Thu, 10 Oct 2019 07:40:18 -0400 Received: by mail-lj1-f194.google.com with SMTP id y3so5843002ljj.6 for ; Thu, 10 Oct 2019 04:40: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=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=w/wpfkf4JD7NtMhgYW5bka2jwABBrG/zFpdfSK+C6Y8ZEzk1usOy+0SZ037SEiwojW 8ikm7DR8YcoaSKOsLXm8/4fAoU66XIkDrdXmlfD0bKpQ4pPfXVVdHhNQ8eWlxdKdwF8m 3v9pJu7MyhXBh0O8lxuIkg9S/oSY3v5jPH/hUxyxae9He70A2JNrMcErYiipUzzxW6la RPJBm1dTBVGovcLV6kmCCd3lqZrimb7rDvRlZSKv2Ch/iQaQuACu1Dssa3Z+C2w/ecWr XF0jqnbdyn9OWFCh7gZX9bj7CuKUEM3iw2jfcQG61bDXCjKqE62EJgVMKO9gnqC4ni9I rSlQ== 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=zajMnk2cgVpbetFqzeuJjqL5gocttncCIISD2oCeqro=; b=XTiiHPaca3zKfvED602tFMW3tgK1ZoBUOflcvaMo/6Zbf/FYVHZHdQZS+rthdaa11s CXn/AFGvjCcm1WErZBV2mQlVxXFawqfJ/KB6iK/HFIQrZESH9quYof+xRRkJ26ATiZBk 6bc8bdOamR9tc251oTt6sv/KHngKokwp5NaGiYYHWpo+1LZ2W5jV0ieV6bxk5RtTa9v3 vwnrCYhDx3k8FIkO8djNeWUDsyCh2S6WermMgYFTwu3pMQD9m+2k5sR0zzUSgTSWLj8h S/rJtqj2Ih1nNW4lpInXqAWp5kNOuUZl8ovaH6IYp+7nE+DsUl4/X0tBUbdT/vKFsR2s Bpfg== X-Gm-Message-State: APjAAAWLtMgJ9VD2Eg5AcWEaNColfaYnbE7gIrP+oSrB9mTzjqr7J/18 MyBn/pOcj63VkziHGAHgM2VbLw== X-Received: by 2002:a2e:87ca:: with SMTP id v10mr5973843ljj.43.1570707614837; Thu, 10 Oct 2019 04:40:14 -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 p3sm1168937ljn.78.2019.10.10.04.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 04:40:14 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Daniel Lezcano , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Lina Iyer , linux-pm@vger.kernel.org Cc: Rob Herring , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 06/13] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Thu, 10 Oct 2019 13:39:30 +0200 Message-Id: <20191010113937.15962-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191010113937.15962-1-ulf.hansson@linaro.org> References: <20191010113937.15962-1-ulf.hansson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Iterating through the idle state nodes in DT, to find out the number of states that needs to be allocated is unnecessary, as it has already been done from dt_init_idle_driver(). Therefore, drop the iteration and use the number we already have at hand. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 2e91c8d6c211..1195a1056139 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -73,28 +73,22 @@ static int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) return 0; } -static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) +static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, + unsigned int state_nodes, int cpu) { - int i, ret = 0, count = 0; + int i, ret = 0; 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(state_nodes, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 0; i < count; i++) { + for (i = 0; i < 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); @@ -104,6 +98,11 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } + if (i != 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; @@ -113,7 +112,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } -static __init int psci_cpu_init_idle(unsigned int cpu) +static __init int psci_cpu_init_idle(unsigned int cpu, unsigned int state_nodes) { struct device_node *cpu_node; int ret; @@ -129,7 +128,7 @@ static __init int psci_cpu_init_idle(unsigned int cpu) if (!cpu_node) return -ENODEV; - ret = psci_dt_cpu_init_idle(cpu_node, cpu); + ret = psci_dt_cpu_init_idle(cpu_node, state_nodes, cpu); of_node_put(cpu_node); @@ -185,7 +184,7 @@ static int __init psci_idle_init_cpu(int cpu) /* * Initialize PSCI idle states. */ - ret = psci_cpu_init_idle(cpu); + ret = psci_cpu_init_idle(cpu, ret); if (ret) { pr_err("CPU %d failed to PSCI idle\n", cpu); goto out_kfree_drv;