From patchwork Tue Oct 29 16:44:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 178037 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp51885ill; Tue, 29 Oct 2019 09:44:54 -0700 (PDT) X-Received: by 2002:a2e:b5d0:: with SMTP id g16mr220329ljn.88.1572367494348; Tue, 29 Oct 2019 09:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572367494; cv=none; d=google.com; s=arc-20160816; b=F+HPL+dxNzRKms6lY0PrmtYyKdkiPfgRxaLTP6JTvPj2u79puP+3sYH5gi/ziNc7Tp 3dCugZb3dEc8itxQL3QH3fQ+Q7+ZFFUYFsKZDZqcqdZ3jNhu1brh9gJwo+r4vjxH1r2r dfpOO19tQnf60DeAuO1Lq8R5WAreJZxvvxqAP3nI2COnXm4HvEl9fchg99Y93nf/MRre N1RjV23Wwa2MnjL0CyFctiSrwThWQSYpU9E9Ht/t43JBmphVExQYWUo0WppYPc2oQm3c B3f4STZKnBwdWCp/jnRmQvj4YERWc/GgNDknLT1tVMOXRmu9tpJNz0aPSKXl1SRlgBFf 4PUg== 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=lVOXUxxNfV4wN8bXUUjCt19F2H674agulhVmSpBAGAE=; b=YGrAfZtTL1/Yp5/oop0PTmLrkDsQ8mSsBwrbkoAHI+bVR7U+V/dLUB1eKFEibDOQPu nA85Akt3bfgz39zNtSaMlymdlA11AAEB5KXWrOiFiyjnGfOtjH9D7ewUNRzycl6UTZEl QG5qwNrwxBe6K1xtvCmgMfxcSkKCtxB9pqOch/toesqyY+j/+HeICi0rxwP7PycJ7Vkm OY14BrkaGzpdoqg/5GA7vkZ/Se8fgbgOhz5ZGHkgsy75pBj5DO59k5Y0lsB08hqJI9xv W1PK2VlH2NgTLTkNHBg5tcE0qQdfAj2ZmSdwJJCoQeN5AKnUudg6eRV5VHNQs165riq2 Ct8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wq5NfHQP; 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 k186sor3910244lfk.12.2019.10.29.09.44.54 for (Google Transport Security); Tue, 29 Oct 2019 09:44:54 -0700 (PDT) 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=Wq5NfHQP; 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=lVOXUxxNfV4wN8bXUUjCt19F2H674agulhVmSpBAGAE=; b=Wq5NfHQPAlEsbZnoQSMFmjC6IAkDnAhfODokHmgWVS89BHlzxBq+ZIf8QlWoglh0YS 4TeLiSC2uYyogVPZ3eCnP0EuopYnwKNk6DKy0T/tPABYmb6JOUPxItn2XxgeuAuSCWpq OudHPaKwaUZRxh/QMpMbNhOjU2IZ2Q8cIzpFzc7tLvhIoGa1oFjLfmpIIbsmbAPEXOQL HRdAyY1mdURR5DmHxMN5wRmFt9zw1oS9mLzxxVM+T5b7WILz0Sx81Jg9XXWGRdz4YURc Jg67ktqi3/B61awY2CkjMd5/w09MMl3vU1SwFJXpNNHKp7Xt5yFrq3EiH/oH55ELcysM DT2A== 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=lVOXUxxNfV4wN8bXUUjCt19F2H674agulhVmSpBAGAE=; b=iG8L2qN2ECqCoqTkHvAa1xlPG50AT4WdGSUO7e7TcU5gwQL6KjJ1hYqJrhIrYb6vAm XC1z4Ow243nkp/Kn50Q9bQIb8Z3h9MXVY6l9EAu5xE0k5GenFfUYf/+Q0B+hAGRRpBe6 21JRlJHLeATkdCcI2bkKofxMXpA6HCS7gLWhMnhWoTEwDbwwslZFi94OFcoR6B8wJPt6 QLrg3vT82L7F+YGglkGi7lIXSJz6HIvp9m4cf0hjWJvmfNq48dYWPlJ/m8/+cKkVKCe2 iD/RGqkOWpfk1iIMaEvE16G+R4X3frP8plLD79koBh0q8+H4L27KAEPDMRSSpQab/Kmt N6WQ== X-Gm-Message-State: APjAAAU2r2GwuV7n6pfqxzc3PrpH8uk+Zc439mKQJ5uqTCzvCWMtGtq7 7FsIECuFgUBxd2K1/ezbRI0JnQeu X-Google-Smtp-Source: APXvYqxGf8w8I3KVuSqOM7/zKsnP0xinWPh7Ee1N9tyxQPh9MinelvopEFVFU27e5Ky+H/l8+CQgXw== X-Received: by 2002:ac2:5b42:: with SMTP id i2mr3123478lfp.164.1572367493929; Tue, 29 Oct 2019 09:44:53 -0700 (PDT) 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 f28sm2048161lfh.35.2019.10.29.09.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 09:44:53 -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 , Andy Gross , Bjorn Andersson , Kevin Hilman , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v2 06/13] cpuidle: psci: Simplify OF parsing of CPU idle state nodes Date: Tue, 29 Oct 2019 17:44:31 +0100 Message-Id: <20191029164438.17012-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191029164438.17012-1-ulf.hansson@linaro.org> References: <20191029164438.17012-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 --- Changes in v2: - Rebased. - Renamed variable and fixed tab-intendent. --- 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;