return 0;
}
-/* Get and set the current governor. */
-EXPORT int hal_power_dvfs_get_curr_governor(unsigned int res_type,
- char *res_name, char *governor)
+static int is_valid_param(char *res_name)
{
- struct pass_resource_dvfs_ops *dvfs;
+ if (!g_power_funcs)
+ return -ENOTSUP;
+ else if (!res_name)
+ return -EINVAL;
+ return 0;
+}
+static int is_valid_param_with_str(char *res_name, char *str)
+{
if (!g_power_funcs)
return -ENOTSUP;
+ else if (!res_name || !str)
+ return -EINVAL;
+ return 0;
+}
- if (!res_name || !governor)
+static int is_valid_param_with_int(char *res_name, int val)
+{
+ if (!g_power_funcs)
+ return -ENOTSUP;
+ else if (!res_name || val < 0)
return -EINVAL;
+ return 0;
+}
+
+/* Get and set the current governor. */
+EXPORT int hal_power_dvfs_get_curr_governor(unsigned int res_type,
+ char *res_name, char *governor)
+{
+ struct pass_resource_dvfs_ops *dvfs;
+ int ret;
+
+ ret = is_valid_param_with_str(res_name, governor);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_set_curr_governor(unsigned int res_type, char *res_name, char *governor)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || !governor)
- return -EINVAL;
+ ret = is_valid_param_with_str(res_name, governor);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_curr_freq(unsigned int res_type, char *res_name)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_min_freq(unsigned int res_type, char *res_name)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_set_min_freq(unsigned int res_type, char *res_name, int freq)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || freq < 0)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, freq);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_max_freq(unsigned int res_type, char *res_name)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_set_max_freq(unsigned int res_type, char *res_name, int freq)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || freq < 0)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, freq);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_available_min_freq(unsigned int res_type, char *res_name)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_available_max_freq(unsigned int res_type, char *res_name)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_up_threshold(unsigned int res_type, char *res_name)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_set_up_threshold(unsigned int res_type, char *res_name, int up_threshold)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || up_threshold < 0)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, up_threshold);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_dvfs_get_load_table(unsigned int res_type, char *res_name, void *pass_cpu_load_table)
{
struct pass_resource_dvfs_ops *dvfs;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
dvfs = get_dvfs(g_power_funcs, res_type);
if (!dvfs)
EXPORT int hal_power_hotplug_get_online_state(unsigned int res_type, char *res_name, int cpu)
{
struct pass_resource_hotplug_ops *hotplug;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || cpu < 0)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, cpu);
+ if (ret < 0)
+ return ret;
hotplug = get_hotplug(g_power_funcs, res_type);
if (!hotplug)
EXPORT int hal_power_hotplug_set_online_state(unsigned int res_type, char *res_name, int cpu, int on)
{
struct pass_resource_hotplug_ops *hotplug;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
+ ret = is_valid_param_with_int(res_name, cpu);
+ if (ret < 0)
+ return ret;
- if (!res_name || cpu < 0 || on < 0)
+ if (on < 0)
return -EINVAL;
hotplug = get_hotplug(g_power_funcs, res_type);
EXPORT int hal_power_hotplug_get_online_min_num(unsigned int res_type, char *res_name)
{
struct pass_resource_hotplug_ops *hotplug;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
hotplug = get_hotplug(g_power_funcs, res_type);
if (!hotplug)
char *res_name, int min_num)
{
struct pass_resource_hotplug_ops *hotplug;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || (min_num < 0))
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, min_num);
+ if (ret < 0)
+ return ret;
hotplug = get_hotplug(g_power_funcs, res_type);
if (!hotplug)
char *res_name)
{
struct pass_resource_hotplug_ops *hotplug;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
hotplug = get_hotplug(g_power_funcs, res_type);
if (!hotplug)
char *res_name, int max_num)
{
struct pass_resource_hotplug_ops *hotplug;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || (max_num < 0))
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, max_num);
+ if (ret < 0)
+ return ret;
hotplug = get_hotplug(g_power_funcs, res_type);
if (!hotplug)
char *res_thermal_name)
{
struct pass_resource_tmu_ops *tmu;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_thermal_name)
- return -EINVAL;
+ ret = is_valid_param(res_thermal_name);
+ if (ret < 0)
+ return ret;
tmu = get_tmu(g_power_funcs, res_type);
if (!tmu)
char *policy)
{
struct pass_resource_tmu_ops *tmu;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_thermal_name || !policy)
- return -EINVAL;
+ ret = is_valid_param_with_str(res_thermal_name, policy);
+ if (ret < 0)
+ return ret;
tmu = get_tmu(g_power_funcs, res_type);
if (!tmu)
int state)
{
struct pass_resource_tmu_ops *tmu;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!cooling_device_name || state < 0)
- return -EINVAL;
+ ret = is_valid_param_with_int(cooling_device_name, state);
+ if (ret < 0)
+ return ret;
tmu = get_tmu(g_power_funcs, device_type);
if (!tmu)
char *cooling_device_name)
{
struct pass_resource_tmu_ops *tmu;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!cooling_device_name)
- return -EINVAL;
+ ret = is_valid_param(cooling_device_name);
+ if (ret < 0)
+ return ret;
tmu = get_tmu(g_power_funcs, device_type);
if (!tmu)
char *cooling_device_name)
{
struct pass_resource_tmu_ops *tmu;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!cooling_device_name)
- return -EINVAL;
+ ret = is_valid_param(cooling_device_name);
+ if (ret < 0)
+ return ret;
tmu = get_tmu(g_power_funcs, device_type);
if (!tmu)
int state)
{
struct pass_resource_battery_ops *charging;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, state);
+ if (ret < 0)
+ return ret;
charging = get_charging(g_power_funcs, device_type);
if (!charging)
char *res_name)
{
struct pass_resource_battery_ops *charging;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
charging = get_charging(g_power_funcs, device_type);
if (!charging)
int charing_current_uA)
{
struct pass_resource_battery_ops *charging;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, charing_current_uA);
+ if (ret < 0)
+ return ret;
charging = get_charging(g_power_funcs, device_type);
if (!charging)
char *res_name)
{
struct pass_resource_battery_ops *charging;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
charging = get_charging(g_power_funcs, device_type);
if (!charging)
char *res_name)
{
struct pass_resource_memory *memory;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name)
- return -EINVAL;
+ ret = is_valid_param(res_name);
+ if (ret < 0)
+ return ret;
switch (res_type) {
case PASS_RESOURCE_MEMORY_ID:
int fault_around_bytes)
{
struct pass_resource_memory *memory;
+ int ret;
- if (!g_power_funcs)
- return -ENOTSUP;
-
- if (!res_name || fault_around_bytes < 0)
- return -EINVAL;
+ ret = is_valid_param_with_int(res_name, fault_around_bytes);
+ if (ret < 0)
+ return ret;
switch (res_type) {
case PASS_RESOURCE_MEMORY_ID: