pass: resmon: Add missing exception handling to check parameter 06/289706/5
authorChanwoo Choi <cw00.choi@samsung.com>
Wed, 8 Mar 2023 21:12:59 +0000 (06:12 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 17 Mar 2023 05:24:21 +0000 (14:24 +0900)
Add missing exception handling to check whether parameter is valid  or not

And fix the wrong function prototype of pass_resmon_unregister_uevent
with the the wrong error log information.

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

index 516bd79..2191452 100644 (file)
@@ -120,6 +120,9 @@ static int resmon_timer_add(struct resmon *monitor, unsigned int interval)
        if (resmon_find_monitor(resmon, RESMON_TIMER, monitor->id))
                return -EINVAL;
 
+       if (interval <= 0 || interval >= UINT_MAX)
+               return -EINVAL;
+
        monitor->id = add_timer_handler(interval, resmon_timer_func, monitor);
        if (!monitor->id)
                return -EPERM;
@@ -153,6 +156,9 @@ static int resmon_timer_update_interval(struct resmon *monitor,
        if (!resmon_find_monitor(resmon, RESMON_TIMER, monitor->id))
                return -EINVAL;
 
+       if (interval <= 0 || interval >= UINT_MAX)
+               return -EINVAL;
+
        /* Update timer interval of timer-based resmon */
        delete_timer_handler(monitor->id);
 
@@ -304,6 +310,10 @@ int pass_resmon_register_timer(struct pass_resource *res,
 
        /* Get instance of struct resmon_ops according to resmon_src_type */
        monitor->ops = resmon_get_ops(src_type);
+       if (!monitor->ops) {
+               ret = -EINVAL;
+               goto err;
+       }
 
        /* Add timer-based resource monitor */
        ret = resmon_timer_add(monitor, timer_interval);
@@ -556,6 +566,7 @@ int pass_resmon_register_uevent(struct pass_resource *res,
        if (!monitor)
                return -ENOMEM;
 
+       monitor->res = res;
        monitor->resmon = resmon;
        monitor->src_type = src_type;
        monitor->user_func = user_func;
@@ -599,7 +610,7 @@ int pass_resmon_unregister_uevent(struct pass_resource *res, guint id)
 
        monitor = resmon_find_monitor(res->resmon, RESMON_UEVENT, id);
        if (!monitor) {
-               _E("failed to find monitor (res_name: %s, type: %d)\n",
+               _E("failed to find monitor (res_name: %s, id: %d)\n",
                                        res->config_data.res_name, id);
                return -EINVAL;
        }
index d23381e..93f4588 100644 (file)
@@ -165,10 +165,9 @@ int pass_resmon_register_uevent(struct pass_resource *res,
  * pass_resmon_unregister_uevent - Unregister uevent-based resource monitor
  *
  * @res: the instance of struct pass_resource
- * @src_type: the type of resource monitor among 'enum resmon_src_type'.
+ * @id: Uevent ID of resource monitor source
  */
-int pass_resmon_unregister_uevent(struct pass_resource *res,
-                               enum resmon_src_type src_type);
+int pass_resmon_unregister_uevent(struct pass_resource *res, guint id);
 
 /**
  * @brief      Prepare PASS_MODULE_RESMON(Resource Monitor) module