halapi: power: Check whether fault_around_bytes input is valid or not 88/276388/4 accepted/tizen/unified/20220622.215414 submit/tizen/20220622.061549
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 14 Jun 2022 10:19:41 +0000 (19:19 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 21 Jun 2022 01:31:31 +0000 (10:31 +0900)
The minimum of fault_around_bytes is 4096 bytes.
In orde to set the default faround_around_bytes,
must use the multiple value of 4096 bytes.

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

index 5917f128897e634350f4a84a30ed1741b3b82ed5..82d1d098ef259802be50a1f1e7ccc9d9803541fb 100644 (file)
@@ -30,6 +30,7 @@
 #endif
 
 #define ARRAY_SIZE(name)       (sizeof(name)/sizeof(name[0]))
+#define FAULT_AROUND_BYTES_4K  4096
 
 static hal_backend_power_funcs *g_power_funcs = NULL;
 static unsigned int g_power_funcs_count = 0;
@@ -850,6 +851,16 @@ EXPORT int hal_power_memory_set_fault_around_bytes(unsigned int res_type,
        if (ret < 0)
                return ret;
 
+       /*
+        * fault_around_bytes should be multiply of page size in order to
+        * prevent the confusion of user. Even if user uses any integer value,
+        * the entered fauled_around_bytes value is rounded by kernel and then
+        * use it. In order to clarify the usage of fauld_around_bytes,
+        * limit the range of value.
+        */
+       if (fault_around_bytes == 0 || (fault_around_bytes % FAULT_AROUND_BYTES_4K))
+               return -EINVAL;
+
        switch (res_type) {
        case PASS_RESOURCE_MEMORY_ID:
                memory = g_power_funcs->memory;