From patchwork Mon Dec 30 14:43:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 182620 Delivered-To: patches@linaro.org Received: by 2002:a92:815a:0:0:0:0:0 with SMTP id e87csp6422245ild; Mon, 30 Dec 2019 06:44:18 -0800 (PST) X-Received: by 2002:a2e:8eda:: with SMTP id e26mr37484761ljl.65.1577717058732; Mon, 30 Dec 2019 06:44:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577717058; cv=none; d=google.com; s=arc-20160816; b=yOX+3UCQ52bogdXkZ92vOm8Be4HcCLBm22CGmBFuYW5OVJbYPfTVjzSwCINUChWgzd ZKhLnuuVGGKaaooaowFx/NM3FfWzIqwBEvoAtzlRlKv0j9gJ1T+T0sTeszM68RPs8sjs +TlRprFhgc1Qi0D7DDOckGEFUQ2IPlc1TgFs29u4WbOolXiNQRxQbrTyK8V9ETAa9KdJ iAxV5h9LIbLNPoAGdUVDDdO+pgFB+dtfVgcelexq43elVvvYYUIErQ3bp44dAspXYsvJ uEf/Qv95rN+aS0fsxF3iPDQWy4wWLiORXtrbwBtmrb5rcQX/wM/WKTk+bUc3AVGKX1X5 NScQ== 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=6qhaKAOOwBUfphZITjOkaySj3WTdBaYmHNTmS8ilyv4=; b=DXfl9MYrs3HJ/wkpShcOmaBpFie8p/vYxcuSWp0IhEP2UfpF5FPr7mHV6YNYLcrRsy IWRjHCloGwqh9bzoUZE3CgC6cUFAI/ByO2suH6tuOWOTf1bFIJafgwhLfajW+0zBCSlV 50AiH7wL9ZAg4r+pttP2amuxuw4xWEGUUOrBQpfSR+fooe5vgiQl2zBIVsmTmCGbSRC7 dgvX/dqGKAKuJamoUQx7Jl9Rr+byXhQI84j3FzI6DkXwijUBHbwAZSTc81CCH7GhOWIp zpsohHhJUqDkhFzRCAk97jOvqGsDSRT3YRkWbUJlSLxi2nyYvjRLZ89gOoI8EiNizvO1 4/1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wG7mQUko; 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 v15sor19667923ljh.7.2019.12.30.06.44.18 for (Google Transport Security); Mon, 30 Dec 2019 06:44:18 -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=wG7mQUko; 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=6qhaKAOOwBUfphZITjOkaySj3WTdBaYmHNTmS8ilyv4=; b=wG7mQUkoPejsVwzXXOR08qaX/pB5VvQfRie7bMqeCEZDWX6/8m1lt3cS7XNawUn2xu XMe4fcnuL8f9C0vHRJKGysck8qxoOMC50DHral3znLUFRh4dFzTa7cBTRvdiBY9RGsiJ 2uMf3PGS38C96bB3TAoX/OpgAVZDIus7XktEp05Y0clIcfD4bxDP0Vyj8HEq4lIKuzdy TDUIRxVUXm/kzgxN6BVIPqMzTYHNg4QmGEfyfbaruTVN5RulSwBpkD3XhfpD0ynnicdb MFoEgkcs0R0oX04FnDByktNiRwyDuiGeA7Ndor1L21m4KpMXcfjf60XZ3kXh3pc/fE9n YROg== 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=6qhaKAOOwBUfphZITjOkaySj3WTdBaYmHNTmS8ilyv4=; b=TR3aznVRIXw7o4GBuKCypg/rkWOudPX3LyzuDYQbvLeRAOB8UPIgPrqkkfxpeEReRM qhf6FteCA28p58ttjU1JuaOOrn4aDcV1HljfCGemUmhScloJgYVB8rkX+USgS+MiBQN/ eVIvR4tn2n0WXKP0KRoDmLggLkdLRKz7ag2TL1clD7bhprFSH+HZ0spUTULKx80pPSsx kua9JKCX0Zg4gMF7NEPvjsVQf31C2fGIB3vFS46bK5hyO+hTL+/k17j55lX21aGwSn+3 IBaot6cq4d61G+E6gX9G7+KKsKMd4pl6pFpyXvle68jReVTSpKtXLl2+ZIXipYQYDH5o TiVw== X-Gm-Message-State: APjAAAXyd+f7E+pXs/4SXp/YSFOUqECPDhmQk5PyEwImyhsyzCPYITnf Rd/FMTLrveAuUszYQVb+aiYpfX7F X-Google-Smtp-Source: APXvYqzo7w+nzPjrwX/azlK6JCTeEG0nxZOnfsmsZ5aML/2fh5jWYLvgMQF5SaNVyXhNasLRLg8J8Q== X-Received: by 2002:a05:651c:327:: with SMTP id b7mr37221036ljp.22.1577717058420; Mon, 30 Dec 2019 06:44:18 -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 a21sm18744931lfg.44.2019.12.30.06.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 06:44:17 -0800 (PST) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Rob Herring , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Vincent Guittot , Stephen Boyd , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v5 06/15] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Mon, 30 Dec 2019 15:43:53 +0100 Message-Id: <20191230144402.30195-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191230144402.30195-1-ulf.hansson@linaro.org> References: <20191230144402.30195-1-ulf.hansson@linaro.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 Reviewed-by: Sudeep Holla --- Changes in v5: - None. --- drivers/cpuidle/cpuidle-psci.c | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 361985f52ddd..761359be50f2 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -73,30 +73,24 @@ 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_count, 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; - - count++; /* Add WFI state too */ - psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + state_count++; /* Add WFI state too */ + psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL); if (!psci_states) return -ENOMEM; - for (i = 1; i < count; i++) { + for (i = 1; i < state_count; i++) { state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i - 1); + if (!state_node) + break; + ret = psci_dt_parse_state_node(state_node, &psci_states[i]); of_node_put(state_node); @@ -106,6 +100,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_count) { + ret = -ENODEV; + goto free_mem; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; return 0; @@ -115,7 +114,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_count) { struct device_node *cpu_node; int ret; @@ -131,7 +130,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_count, cpu); of_node_put(cpu_node); @@ -187,7 +186,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;