Imported Upstream version 1.1.2
[psensor-pkg-ubuntu.git] / src / lib / amd.c
index e83f5f1..c2ec5eb 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <adl_sdk.h>
 
-#include "psensor.h"
+#include <psensor.h>
 
 typedef int (*ADL_MAIN_CONTROL_CREATE)(ADL_MAIN_MALLOC_CALLBACK, int);
 typedef int (*ADL_MAIN_CONTROL_DESTROY)();
@@ -76,10 +76,11 @@ static double get_temp(struct psensor *sensor)
 
        v.iSize = sizeof(ADLTemperature);
        v.iTemperature = -273;
+
        if (ADL_OK == adl_od5_temperature_get(sensor->amd_id, 0, &v))
                return v.iTemperature/1000;
-       else
-               return UNKNOWN_DBL_VALUE;
+
+       return UNKNOWN_DBL_VALUE;
 }
 
 static double get_fanspeed(struct psensor *sensor)
@@ -89,10 +90,11 @@ static double get_fanspeed(struct psensor *sensor)
        v.iSize = sizeof(ADLFanSpeedValue);
        v.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM;
        v.iFanSpeed = -1;
+
        if (ADL_OK == adl_od5_fanspeed_get(sensor->amd_id, 0, &v))
                return v.iFanSpeed;
-       else
-               return UNKNOWN_DBL_VALUE;
+
+       return UNKNOWN_DBL_VALUE;
 }
 
 static double get_usage(struct psensor *sensor)
@@ -100,10 +102,11 @@ static double get_usage(struct psensor *sensor)
        ADLPMActivity v;
 
        v.iSize = sizeof(ADLPMActivity);
+
        if (ADL_OK == adl_od5_currentactivity_get(sensor->amd_id, &v))
                return v.iActivityPercent;
-       else
-               return UNKNOWN_DBL_VALUE;
+
+       return UNKNOWN_DBL_VALUE;
 }
 
 static struct psensor *create_sensor(int id, int type, int values_len)
@@ -130,7 +133,7 @@ static struct psensor *create_sensor(int id, int type, int values_len)
        /* GPU Usage (Activity/Load %) */
        case 2:
                sprintf(name, "AMD GPU%d Usage", id);
-               sensor_type |= SENSOR_TYPE_GPU | SENSOR_TYPE_USAGE;
+               sensor_type |= SENSOR_TYPE_GPU | SENSOR_TYPE_PERCENT;
                break;
        }
 
@@ -268,7 +271,7 @@ void amd_psensor_list_update(struct psensor **sensors)
                                psensor_set_current_value(s, get_temp(s));
                        else if (s->type & SENSOR_TYPE_RPM)
                                psensor_set_current_value(s, get_fanspeed(s));
-                       else if (s->type & SENSOR_TYPE_USAGE)
+                       else if (s->type & SENSOR_TYPE_PERCENT)
                                psensor_set_current_value(s, get_usage(s));
                }
 
@@ -277,28 +280,19 @@ void amd_psensor_list_update(struct psensor **sensors)
 }
 
 /* Entry point for AMD sensors */
-struct psensor * *
-amd_psensor_list_add(struct psensor **sensors, int values_len)
+void amd_psensor_list_append(struct psensor ***sensors, int values_len)
 {
        int i, j, n;
-       struct psensor **tmp, **ss, *s;
+       struct psensor *s;
 
        n = init();
 
-       ss = sensors;
        for (i = 0; i < n; i++)
                /* Each GPU Adapter has 3 sensors: temp, fan speed and usage */
                for (j = 0; j < 3; j++) {
                        s = create_sensor(i, j, values_len);
-                       tmp = psensor_list_add(ss, s);
-
-                       if (ss != tmp)
-                               free(ss);
-
-                       ss = tmp;
+                       psensor_list_append(sensors, s);
                }
-
-       return ss;
 }
 
 void amd_cleanup()