This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 515c3978dd4b21eda1b37acfe97dc629b08cdd53
Author: wangjianyu3 <[email protected]>
AuthorDate: Mon Dec 18 22:08:24 2023 +0800

    Thermal: Check trip type in thermal_zone_device_register().
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 drivers/thermal/thermal_core.c | 10 ++++++++++
 include/nuttx/thermal.h        |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 619194857c..0f5f2fc46b 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -678,6 +678,7 @@ thermal_zone_device_register(FAR const char *name,
   FAR struct thermal_governor_s *gov;
   FAR struct thermal_zone_device_s *pos;
   FAR struct thermal_zone_device_s *zdev;
+  int i;
 
   if (!ops || !ops->get_temp)
     {
@@ -685,6 +686,15 @@ thermal_zone_device_register(FAR const char *name,
       return NULL;
     }
 
+  for (i = 0; i < params->num_trips; i++)
+    {
+      if (params->trips[i].type >= THERMAL_TRIP_TYPE_MAX)
+        {
+          therr("Invalid trip type (%d)!\n", params->trips[i].type);
+          return NULL;
+        }
+    }
+
   nxmutex_lock(&g_thermal_lock);
 
   list_for_every_entry(&g_zone_dev_list, pos,
diff --git a/include/nuttx/thermal.h b/include/nuttx/thermal.h
index 53a7c668a2..22bcce71a4 100644
--- a/include/nuttx/thermal.h
+++ b/include/nuttx/thermal.h
@@ -69,10 +69,10 @@ enum thermal_trend_e
 
 enum thermal_trip_type_e
 {
-  THERMAL_COLD,
   THERMAL_NORMAL,
   THERMAL_HOT,
   THERMAL_CRITICAL,
+  THERMAL_TRIP_TYPE_MAX,
 };
 
 struct thermal_governor_s

Reply via email to