Re: [PATCH v2 2/3] cpuidle:powernv: Add helper function to populate powernv idle states.
From: Paul Mackerras <hidden>
Date: 2016-11-01 21:03:09
Also in:
linux-pm, lkml
On Tue, Nov 01, 2016 at 07:32:58PM +1100, Oliver O'Halloran wrote:
On Thu, Oct 27, 2016 at 7:35 PM, Gautham R. Shenoy [off-list ref] wrote:quoted
From: "Gautham R. Shenoy" <redacted> In the current code for powernv_add_idle_states, there is a lot of code duplication while initializing an idle state in powernv_states table. Add an inline helper function to populate the powernv_states[] table for a given idle state. Invoke this for populating the "Nap", "Fastsleep" and the stop states in powernv_add_idle_states. Signed-off-by: Gautham R. Shenoy <redacted> --- drivers/cpuidle/cpuidle-powernv.c | 82 +++++++++++++++++++++++---------------- include/linux/cpuidle.h | 1 + 2 files changed, 49 insertions(+), 34 deletions(-)diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c index 7fe442c..11b22b9 100644 --- a/drivers/cpuidle/cpuidle-powernv.c +++ b/drivers/cpuidle/cpuidle-powernv.c@@ -167,6 +167,28 @@ static int powernv_cpuidle_driver_init(void) return 0; } +static inline void add_powernv_state(int index, const char *name, + unsigned int flags, + int (*idle_fn)(struct cpuidle_device *, + struct cpuidle_driver *, + int), + unsigned int target_residency, + unsigned int exit_latency, + u64 psscr_val) +{ + strncpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN); + strncpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);If the supplied name is equal to CPUIDLE_NAME_LEN then strncpy() won't terminate the string. The least annoying fix is to memset() the whole structure to zero and set n to CPUIDLE_NAME_LEN - 1.
Or he could use strlcpy() instead of strncpy(). Paul.