From patchwork Wed Nov 27 10:29:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 180284 Delivered-To: patches@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp5914460ilf; Wed, 27 Nov 2019 02:29:27 -0800 (PST) X-Received: by 2002:a2e:b007:: with SMTP id y7mr30053425ljk.69.1574850567598; Wed, 27 Nov 2019 02:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574850567; cv=none; d=google.com; s=arc-20160816; b=Kxrn8tw3yzpsom0urrvUXA+ivHZh4ZXInFA7mCq/Ok+LgQw8M6aiVH3UM/80p1vgCT bTYK9skZGry8RkCsd+dXA28ezu4v+SjUitDbX8GOHozvrrKaHSgxClZh6ZMhpgD055ce Yh9tFJYXAv6OGdoWTo369BQ7oszj3Cf17ImOsVfQrS5ByNXCeGpWO/nWeYAY5U5Y2GX8 QyQjH7bCYkzRWWJ56pQQ8KwDEsfgTZwR/p/rBkfKu2H/lhKtWTCRcOg0qjvXy3s6hiOE 12vzjXDVCtbWNAstGINkQ2HQ5CrYvCADa+hivvSduvpN2xE3DT2WCRP1N9NbVD1e7Jg9 Sn7Q== 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=0I9CQqrUBNSTNqaPoYCSgGHqC9smjnctVcF6YeNShSQ=; b=mUms9UEetzyRxdOgb9ugaj7C7vRlsCA52nuoLj/pcRgbyDGuoPtYIeuIMoQxHn/9B/ 99kN4WlYiVKLVAtFOBr/pr4wEQQd4MWqzA+mWFcqEgEQmNBQKoXFOtKNoyNp+6tfj7Ix /J8UzMLN0x5s36hnPMasX22SHDfJCYAUocriHkhMMD65UHYMJ6KLNIJfhd6Jco5GO1jq 2drStTwyh2cILO0P2cy9R0AxeGLY3cWBX81Vm6ypmB6wopZvo89RZ472WJdU6ZjKARnn mqemTuTqDa10Kt0KTC9Gjq5tKm9yVrpZ1RyDXlEtPm9AhjwNx5zuegoRAX6pNdIzcO6U AYDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vZ1vOFaH; 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 o68sor3736361lff.59.2019.11.27.02.29.27 for (Google Transport Security); Wed, 27 Nov 2019 02:29:27 -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=vZ1vOFaH; 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=0I9CQqrUBNSTNqaPoYCSgGHqC9smjnctVcF6YeNShSQ=; b=vZ1vOFaHIZmtCdVywrWmJBZGQYGImGUJFdgpnJpTpl9g9lZQrdtiKa347hWKoVT80M 2ui5XajnnMJ2OqZe4jTjaj6WoYmEaPHvpSpjJVAlkpqIEfv0Y1TLqmeCOQq1i+nWax2E 5ZwTRG1xMvRIj8zQ/E/62lyspn9awdC/GJEmr5HNssUDKOjdv8LcTflXAXXYepmrrwSQ fQ4DEY6vociDIPd9KFLaCtvFZo9F0nNRnCCwSaoFWrz4OdLn2wETIbPvI6Drbgzbezzl vCXF1Jm6ldsz1uIfzHl8kckcS66a8S5yo1Vd03uGTo2LXIXjUj92xStSzceDPHBUe0bI n5Nw== 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=0I9CQqrUBNSTNqaPoYCSgGHqC9smjnctVcF6YeNShSQ=; b=tJyn09WMwjb1OwiNGPMMrcqlCvHlFqhRrmrmms7eVhhe0xhES6FAzbDwAZCQjBDOvD 0FuoX9knJcLOP0STIztBumcVdGc8Adq5QNxY1d2Ws/kvl1U4SZEYSgXeoetmLC1IJ91y gIlDTPllzPTJmfd7LnhwhlnC7XRzX3umxVtjGC43Mnj7DSLq1teyMAiQpZOvXoZG46Yg vKEvuxFrAYfhmU5lBeLnSJQC5eLw3aFpMlX6zFfzkcDSXAJGLi9yY7fK9u2JVpSZ3r+N dbVonkzyGP5gVOMU4NAlegiR//bD7Hw0TagcT34xuKmvjiMmqRrjIyicISsDFL14nU7z 4hjQ== X-Gm-Message-State: APjAAAU+Ww+7CjB+BkWQqrkRWb34idEjdHwLP4Lrql1tbYJQrJjhHfJt gHMDeIhyYk0ZoSg0QbXGsj0wd+yG X-Google-Smtp-Source: APXvYqwNFTas3Bs6wwHxVh132p8pvVvuXzBhsyjzWLzItUAMqGGEB3v2xG26muuVMBiwA8d0S7N2BQ== X-Received: by 2002:ac2:5ec3:: with SMTP id d3mr1270912lfq.176.1574850567136; Wed, 27 Nov 2019 02:29:27 -0800 (PST) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id t9sm6868260ljj.19.2019.11.27.02.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 02:29:26 -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 v3 06/13] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Wed, 27 Nov 2019 11:29:07 +0100 Message-Id: <20191127102914.18729-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191127102914.18729-1-ulf.hansson@linaro.org> References: <20191127102914.18729-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 v3: - 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;