changed copyright dates to 2012.
[psensor.git] / src / lib / amd.c
index 93428b8..e7befe5 100644 (file)
@@ -1,21 +1,22 @@
 /*
-    Copyright (C) 2010-2011 thgreasi@gmail.com
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301 USA
-*/
+ * Copyright (C) 2010-2011 thgreasi@gmail.com, jeanfi@gmail.com
+ * Copyright (C) 2010-2012 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
 #ifndef LINUX
 #define LINUX 1
 #endif
@@ -60,22 +61,13 @@ static int *active_amd_adapters;
 /* Memory allocation function */
 static void __stdcall *adl_main_memory_alloc(int isize)
 {
-    void *lpbuffer = malloc(isize);
-    return lpbuffer;
-}
-
-/* Optional Memory de-allocation function */
-static void __stdcall adl_main_memory_free(void **lpbuffer)
-{
-       if (*lpbuffer) {
-               free(*lpbuffer);
-               *lpbuffer = NULL;
-       }
+       void *lpbuffer = malloc(isize);
+       return lpbuffer;
 }
 
 static void *getprocaddress(void *plibrary, const char * name)
 {
-    return dlsym(plibrary, name);
+       return dlsym(plibrary, name);
 }
 
 /*
@@ -126,8 +118,8 @@ static struct psensor *create_sensor(int id, int values_len)
                sensor_type = SENSOR_TYPE_AMD_TEMP;
        }
 
-       sid = malloc(strlen("AMD") + 1 + strlen(name) + 1);
-       sprintf(sid, "AMD %s", name);
+       sid = malloc(strlen("amd") + 1 + strlen(name) + 1);
+       sprintf(sid, "amd %s", name);
 
        s = psensor_create(sid, strdup(name),
                           sensor_type, values_len);
@@ -146,7 +138,7 @@ static struct psensor *create_sensor(int id, int values_len)
 static int init()
 {
        LPAdapterInfo lpadapterinfo = NULL;
-       int  i, inumberadapters, inumberadaptersactive = 0;
+       int i, inumberadapters, inumberadaptersactive = 0;
        int lpstatus, iadapterindex;
 
        hdll = NULL;
@@ -205,16 +197,18 @@ static int init()
        if (!inumberadapters)
                return 0;
 
-    lpadapterinfo = malloc(sizeof(AdapterInfo) * inumberadapters);
-    memset(lpadapterinfo, '\0', sizeof(AdapterInfo) * inumberadapters);
+       lpadapterinfo = malloc(sizeof(AdapterInfo) * inumberadapters);
+       memset(lpadapterinfo, '\0', sizeof(AdapterInfo) * inumberadapters);
+
+       /* Get the AdapterInfo structure for all adapters in the system */
+       adl_adapter_adapterinfo_get(lpadapterinfo,
+                                   sizeof(AdapterInfo) * inumberadapters);
 
-    /* Get the AdapterInfo structure for all adapters in the system */
-    adl_adapter_adapterinfo_get(lpadapterinfo,
-                sizeof(AdapterInfo) * inumberadapters);
+       /* Repeat for all available adapters in the system */
+       for (i = 0; i < inumberadapters; i++) {
 
-    /* Repeat for all available adapters in the system */
-    for (i = 0; i < inumberadapters; i++) {
                iadapterindex = lpadapterinfo[i].iAdapterIndex;
+
                if (ADL_OK != adl_adapter_active_get(iadapterindex, &lpstatus))
                        continue;
                if (lpstatus != ADL_TRUE)
@@ -226,18 +220,18 @@ static int init()
                        inumberadaptersactive = 1;
                } else {
                        ++inumberadaptersactive;
-                       active_amd_adapters =
-                                (int *) realloc(active_amd_adapters,
+                       active_amd_adapters = (int *)realloc
+                               (active_amd_adapters,
                                 sizeof(int)*inumberadaptersactive);
                }
                active_amd_adapters[inumberadaptersactive-1] = iadapterindex;
-    }
+       }
 
-    adl_main_memory_free((void **) &lpadapterinfo);
+       free(lpadapterinfo);
 
-    /* Each Adapter has one GPU temperature
-       sensor and one fan control sensor */
-    return 2*inumberadaptersactive;
+       /* Each Adapter has one GPU temperature sensor and one fan
+          control sensor */
+       return 2*inumberadaptersactive;
 }
 
 void amd_psensor_list_update(struct psensor **sensors)