pass: hal: Add missing parameter validation 75/276575/3 accepted/tizen/unified/20220628.133607 submit/tizen/20220623.085905
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 21 Jun 2022 03:05:45 +0000 (12:05 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 23 Jun 2022 06:08:12 +0000 (15:08 +0900)
If enter the wrong value, it cause the fault and wrong operation.
So that add the missing parameter validation checking
to prevent the wrong operation. Add missing parameter validation
by using the unittest result of pass-hal module.

- Detailed the unittest result of pass-hal module
[  FAILED  ] PassHalTest.pass_hal_set_online_state (7 ms)
[  FAILED  ] PassHalTest.pass_hal_set_cooling_device_state (1 ms)
[  FAILED  ] PassHalTest.pass_hal_set_battery_charging_status (1 ms)
[  FAILED  ] PassHalTest.pass_hal_set_battery_charging_current (1 ms)
[  FAILED  ] PassHalTest.pass_hal_set_fault_around_bytes (1 ms)

Change-Id: Id320b77188508d82bc68137c65bb5b7d81729c55
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/pass/pass-hal.c

index f5d81b5..a5a679d 100644 (file)
@@ -277,7 +277,10 @@ int pass_hal_get_online_state(struct pass_resource *res, int cpu)
  */
 int pass_hal_set_online_state(struct pass_resource *res, int cpu, int on)
 {
-       if (!res || cpu < 0 || on < 0)
+       if (!res || cpu < 0)
+               return -EINVAL;
+
+       if (on != 0 && on != 1)
                return -EINVAL;
 
        return hal_power_hotplug_set_online_state(res->config_data.res_type,
@@ -434,7 +437,7 @@ int pass_hal_get_cooling_device_state(struct pass_resource *res)
  */
 int pass_hal_set_cooling_device_state(struct pass_resource *res, int state)
 {
-       if (!res)
+       if (!res || state < 0)
                return -EINVAL;
 
        /*
@@ -480,7 +483,7 @@ int pass_hal_get_cooling_device_max_state(struct pass_resource *res)
  */
 int pass_hal_set_battery_charging_status(struct pass_resource *res, int charging_status)
 {
-       if (!res)
+       if (!res || charging_status < 0)
                return -EINVAL;
 
        return hal_power_battery_set_charging_status(res->config_data.res_type,
@@ -517,7 +520,7 @@ int pass_hal_get_battery_charging_status(struct pass_resource *res)
 int pass_hal_set_battery_charging_current(struct pass_resource *res,
                                        int charging_current_uA)
 {
-       if (!res)
+       if (!res || charging_current_uA <= 0)
                return -EINVAL;
 
        return hal_power_battery_set_charging_current(res->config_data.res_type,
@@ -555,7 +558,7 @@ int pass_hal_get_battery_charging_current(struct pass_resource *res)
 int pass_hal_set_fault_around_bytes(struct pass_resource *res,
                                int fault_around_bytes)
 {
-       if (!res)
+       if (!res || fault_around_bytes <= 0)
                return -EINVAL;
 
        return hal_power_memory_set_fault_around_bytes(res->config_data.res_type,