Re: [PATCH 05/18] drivers: firmware: psci: Simplify state node parsing

From: Sudeep Holla
Date: Fri Jun 07 2019 - 11:06:03 EST


On Mon, May 13, 2019 at 09:22:47PM +0200, Ulf Hansson wrote:
> 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 <ulf.hansson@xxxxxxxxxx>
> Acked-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
> ---
>
> Changes:
> - None.
>
> ---
> drivers/firmware/psci/psci.c | 25 ++++++++++++-------------
> 1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
> index 88e90e0f06b9..9c2180bcee4c 100644
> --- a/drivers/firmware/psci/psci.c
> +++ b/drivers/firmware/psci/psci.c
> @@ -306,26 +306,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);

Why not start using of_get_cpu_state_node here which was introduced in
earlier patch as part of this simplification ?

--
Regards,
Sudeep