return 0;
 }
 
+static int __init psci_dt_cpu_init_topology(struct cpuidle_driver *drv,
+                                           struct psci_cpuidle_data *data,
+                                           unsigned int state_count, int cpu)
+{
+       /* Currently limit the hierarchical topology to be used in OSI mode. */
+       if (!psci_has_osi_support())
+               return 0;
+
+       data->dev = psci_dt_attach_cpu(cpu);
+       if (IS_ERR_OR_NULL(data->dev))
+               return PTR_ERR_OR_ZERO(data->dev);
+
+       /*
+        * Using the deepest state for the CPU to trigger a potential selection
+        * of a shared state for the domain, assumes the domain states are all
+        * deeper states.
+        */
+       drv->states[state_count - 1].enter = psci_enter_domain_idle_state;
+       psci_cpuidle_use_cpuhp = true;
+
+       return 0;
+}
+
 static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
                                        struct device_node *cpu_node,
                                        unsigned int state_count, int cpu)
                goto free_mem;
        }
 
-       /* Currently limit the hierarchical topology to be used in OSI mode. */
-       if (psci_has_osi_support()) {
-               data->dev = psci_dt_attach_cpu(cpu);
-               if (IS_ERR(data->dev)) {
-                       ret = PTR_ERR(data->dev);
-                       goto free_mem;
-               }
-
-               /*
-                * Using the deepest state for the CPU to trigger a potential
-                * selection of a shared state for the domain, assumes the
-                * domain states are all deeper states.
-                */
-               if (data->dev) {
-                       drv->states[state_count - 1].enter =
-                               psci_enter_domain_idle_state;
-                       psci_cpuidle_use_cpuhp = true;
-               }
-       }
+       /* Initialize optional data, used for the hierarchical topology. */
+       ret = psci_dt_cpu_init_topology(drv, data, state_count, cpu);
+       if (ret < 0)
+               goto free_mem;
 
        /* Idle states parsed correctly, store them in the per-cpu struct. */
        data->psci_states = psci_states;