diff options
author | John Stultz <john.stultz@linaro.org> | 2016-08-18 14:04:34 -0700 |
---|---|---|
committer | John Stultz <john.stultz@linaro.org> | 2016-08-22 23:24:01 -0700 |
commit | e150ab36321e4692cd7a55adc75a027ffcd71a8a (patch) | |
tree | 6286ed0aa6c10370890eb856908a6b56d80d1eee | |
parent | c579371efd42b552781e72ee721fbd540409d231 (diff) | |
download | hikey-e150ab36321e4692cd7a55adc75a027ffcd71a8a.tar.gz |
power_hikey: Use container_of macro instead of just casting
Add container_of macro instead of just blind casting, assuming
the structure is formatted a specific way.
Change-Id: I31368d41e82627ce3e42f3be509a4495fc4d2e12
Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r-- | power/power_hikey.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/power/power_hikey.c b/power/power_hikey.c index a06a0d32..9b28e738 100644 --- a/power/power_hikey.c +++ b/power/power_hikey.c @@ -55,6 +55,11 @@ static bool low_power_mode = false; static char *max_cpu_freq = NORMAL_MAX_FREQ; static char *low_power_max_cpu_freq = LOW_POWER_MAX_FREQ; + +#define container_of(addr, struct_name, field_name) \ + ((struct_name *)((char *)(addr) - offsetof(struct_name, field_name))) + + static void sysfs_write(const char *path, char *s) { char buf[80]; @@ -77,7 +82,7 @@ static void sysfs_write(const char *path, char *s) } /*[interactive cpufreq gov funcs]*********************************************/ -static void interactive_power_init(struct power_module __unused *module) +static void interactive_power_init(struct hikey_power_module __unused *hikey) { int32_t is_svelte = property_get_int32(SVELTE_PROP, 0); @@ -156,14 +161,16 @@ static int interactive_boostpulse(struct hikey_power_module *hikey) static void hikey_power_init(struct power_module __unused *module) { - interactive_power_init(module); + struct hikey_power_module *hikey = container_of(module, + struct hikey_power_module, base); + interactive_power_init(hikey); } static void hikey_power_hint(struct power_module *module, power_hint_t hint, void *data) { - struct hikey_power_module *hikey = - (struct hikey_power_module *) module; + struct hikey_power_module *hikey = container_of(module, + struct hikey_power_module, base); pthread_mutex_lock(&hikey->lock); switch (hint) { @@ -191,8 +198,8 @@ static void hikey_power_hint(struct power_module *module, power_hint_t hint, static void set_feature(struct power_module *module, feature_t feature, int state) { - struct hikey_power_module *hikey = - (struct hikey_power_module *) module; + struct hikey_power_module *hikey = container_of(module, + struct hikey_power_module, base); switch (feature) { default: ALOGW("Error setting the feature, it doesn't exist %d\n", feature); |