File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,28 @@ bool cpuidle_state_is_coupled(struct cpuidle_driver *drv, int state)
186186 return drv -> states [state ].flags & CPUIDLE_FLAG_COUPLED ;
187187}
188188
189+ /**
190+ * cpuidle_coupled_state_verify - check if the coupled states are correctly set.
191+ * @drv: struct cpuidle_driver for the platform
192+ *
193+ * Returns 0 for valid state values, a negative error code otherwise:
194+ * * -EINVAL if any coupled state(safe_state_index) is wrongly set.
195+ */
196+ int cpuidle_coupled_state_verify (struct cpuidle_driver * drv )
197+ {
198+ int i ;
199+
200+ for (i = drv -> state_count - 1 ; i >= 0 ; i -- ) {
201+ if (cpuidle_state_is_coupled (drv , i ) &&
202+ (drv -> safe_state_index == i ||
203+ drv -> safe_state_index < 0 ||
204+ drv -> safe_state_index >= drv -> state_count ))
205+ return - EINVAL ;
206+ }
207+
208+ return 0 ;
209+ }
210+
189211/**
190212 * cpuidle_coupled_set_ready - mark a cpu as ready
191213 * @coupled: the struct coupled that contains the current cpu
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ extern void cpuidle_remove_sysfs(struct cpuidle_device *dev);
3535
3636#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
3737bool cpuidle_state_is_coupled (struct cpuidle_driver * drv , int state );
38+ int cpuidle_coupled_state_verify (struct cpuidle_driver * drv );
3839int cpuidle_enter_state_coupled (struct cpuidle_device * dev ,
3940 struct cpuidle_driver * drv , int next_state );
4041int cpuidle_coupled_register_device (struct cpuidle_device * dev );
@@ -46,6 +47,11 @@ bool cpuidle_state_is_coupled(struct cpuidle_driver *drv, int state)
4647 return false;
4748}
4849
50+ static inline int cpuidle_coupled_state_verify (struct cpuidle_driver * drv )
51+ {
52+ return 0 ;
53+ }
54+
4955static inline int cpuidle_enter_state_coupled (struct cpuidle_device * dev ,
5056 struct cpuidle_driver * drv , int next_state )
5157{
Original file line number Diff line number Diff line change @@ -227,6 +227,10 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
227227 if (!drv || !drv -> state_count )
228228 return - EINVAL ;
229229
230+ ret = cpuidle_coupled_state_verify (drv );
231+ if (ret )
232+ return ret ;
233+
230234 if (cpuidle_disabled ())
231235 return - ENODEV ;
232236
You can’t perform that action at this time.
0 commit comments