mbpfan-josie

Reformat source code with clang-tidy

Run with:

clang-format -i src/*

Closes #233.

623f44d0a58ac67c80244ca972564131cd45a7ed
Andrew Gaul <andrew@gaul.org> · 2021-04-12T22:05 · browse files at this commit

parents: 16f28f9

diff --git a/src/daemon.c b/src/daemon.c
index 3f933e8..760f512 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -16,7 +16,6 @@
  *
  */
 
-
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -43,7 +42,7 @@ int write_pid(int pid)
     FILE *file = NULL;
     file = fopen(PROGRAM_PID, "w");
 
-    if(file != NULL) {
+    if (file != NULL) {
         fprintf(file, "%d", pid);
         fclose(file);
         return 1;
@@ -59,14 +58,13 @@ int read_pid()
     int pid = -1;
     file = fopen(PROGRAM_PID, "r");
 
-    if(file != NULL) {
+    if (file != NULL) {
         fscanf(file, "%d", &pid);
         fclose(file);
-        if (kill(pid, 0) == -1 && errno == ESRCH)
-        { /* a process with such a pid does not exist, remove the pid file */
-          if (remove(PROGRAM_PID) ==  0) {
-            return -1;
-          }
+        if (kill(pid, 0) == -1 && errno == ESRCH) { /* a process with such a pid does not exist, remove the pid file */
+            if (remove(PROGRAM_PID) == 0) {
+                return -1;
+            }
         }
         return pid;
     }
@@ -81,40 +79,40 @@ int delete_pid()
 
 static void cleanup_and_exit(int exit_code)
 {
-	delete_pid();
-	set_fans_auto(fans);
-	
-	struct s_fans *next_fan;
-	while (fans != NULL) {
-		next_fan = fans->next;
-		if (fans->file != NULL) {
-			fclose(fans->file);
-		}
-		free(fans->label);
-		free(fans->fan_output_path);
-		free(fans->fan_manual_path);
-		free(fans);
-		fans = next_fan;
-	}
-
-	struct s_sensors *next_sensor;
-	while (sensors != NULL) {
-		next_sensor = sensors->next;
-		if (sensors->file != NULL) {
-			fclose(sensors->file);
-		}
-		free(sensors->path);
-		free(sensors);
-		sensors = next_sensor;
-	}
-
-	exit(exit_code);
+    delete_pid();
+    set_fans_auto(fans);
+
+    struct s_fans *next_fan;
+    while (fans != NULL) {
+        next_fan = fans->next;
+        if (fans->file != NULL) {
+            fclose(fans->file);
+        }
+        free(fans->label);
+        free(fans->fan_output_path);
+        free(fans->fan_manual_path);
+        free(fans);
+        fans = next_fan;
+    }
+
+    struct s_sensors *next_sensor;
+    while (sensors != NULL) {
+        next_sensor = sensors->next;
+        if (sensors->file != NULL) {
+            fclose(sensors->file);
+        }
+        free(sensors->path);
+        free(sensors);
+        sensors = next_sensor;
+    }
+
+    exit(exit_code);
 }
 
 void signal_handler(int signal)
 {
 
-    switch(signal) {
+    switch (signal) {
     case SIGHUP:
         syslog(LOG_WARNING, "Received SIGHUP signal.");
         retrieve_settings(NULL, fans);
@@ -151,7 +149,7 @@ void go_daemon(void (*fan_control)())
     signal(SIGINT, signal_handler);
 
     // Setup syslog logging - see SETLOGMASK(3)
-    if(verbose) {
+    if (verbose) {
         setlogmask(LOG_UPTO(LOG_DEBUG));
         openlog(PROGRAM_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);
 
@@ -198,15 +196,12 @@ void go_daemon(void (*fan_control)())
             exit(EXIT_FAILURE);
         }
 
-
-
         /* Close out the standard file descriptors */
         close(STDIN_FILENO);
         close(STDOUT_FILENO);
         close(STDERR_FILENO);
     }
 
-
     int current_pid = getpid();
 
     if (read_pid() == -1) {
@@ -229,10 +224,9 @@ void go_daemon(void (*fan_control)())
         exit(EXIT_FAILURE);
     }
 
-
     fan_control();
 
-    if(daemonize) {
+    if (daemonize) {
         syslog(LOG_INFO, "%s daemon exiting", PROGRAM_NAME);
     }
 }
diff --git a/src/daemon.h b/src/daemon.h
index c52c4cc..cb26450 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -50,5 +50,4 @@ void signal_handler(int signal);
  */
 void go_daemon(void (*function)());
 
-
 #endif
diff --git a/src/global.h b/src/global.h
index 4c32551..6eaea36 100644
--- a/src/global.h
+++ b/src/global.h
@@ -9,18 +9,18 @@ extern int daemonize;
 extern int verbose;
 
 struct s_sensors {
-    FILE* file;
-    char* path;
+    FILE *file;
+    char *path;
     unsigned int temperature;
     struct s_sensors *next;
 };
 
 struct s_fans {
-    FILE* file;
-    char* path;  // TODO: unused
-    char* label;
-    char* fan_output_path;
-    char* fan_manual_path;
+    FILE *file;
+    char *path; // TODO: unused
+    char *label;
+    char *fan_output_path;
+    char *fan_manual_path;
     int step_up;
     int step_down;
     int fan_id;
@@ -33,7 +33,7 @@ struct s_fans {
 typedef struct s_sensors t_sensors;
 typedef struct s_fans t_fans;
 
-extern t_sensors* sensors;
-extern t_fans* fans;
+extern t_sensors *sensors;
+extern t_fans *fans;
 
 #endif
diff --git a/src/main.c b/src/main.c
index 41bc86f..7e5f1d6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,7 +31,7 @@
 
 void print_usage(int argc, char *argv[])
 {
-    if (argc >=1) {
+    if (argc >= 1) {
         printf("Usage: %s OPTION(S) \n", argv[0]);
         printf("Options:\n");
         printf("\t-h Show this help screen\n");
@@ -46,8 +46,8 @@ int main(int argc, char *argv[])
 
     int c;
 
-    while( (c = getopt(argc, argv, "hfv|help")) != -1) {
-        switch(c) {
+    while ((c = getopt(argc, argv, "hfv|help")) != -1) {
+        switch (c) {
         case 'h':
             print_usage(argc, argv);
             exit(EXIT_SUCCESS);
diff --git a/src/mbpfan.c b/src/mbpfan.c
index a06880c..01df2f9 100644
--- a/src/mbpfan.c
+++ b/src/mbpfan.c
@@ -47,8 +47,8 @@
 #include "util.h"
 
 /* lazy min/max... */
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#define max(a,b) ((a) > (b) ? (a) : (b))
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#define max(a, b) ((a) > (b) ? (a) : (b))
 
 #define CORETEMP_PATH "/sys/devices/platform/coretemp.0"
 #define APPLESMC_PATH "/sys/devices/platform/applesmc.768"
@@ -57,9 +57,9 @@
  * low_temp - temperature below which fan speed will be at minimum
  * high_temp - fan will increase speed when higher than this temperature
  * max_temp - fan will run at full speed above this temperature */
-int low_temp = 63;   // try ranges 55-63
-int high_temp = 66;  // try ranges 58-66
-int max_temp = 86;   // do not set it > 90
+int low_temp = 63;  // try ranges 55-63
+int high_temp = 66; // try ranges 58-66
+int max_temp = 86;  // do not set it > 90
 
 // maximum number of processors etc supported
 #define NUM_PROCESSORS 6
@@ -72,8 +72,8 @@ int max_temp = 86;   // do not set it > 90
 
 int polling_interval = 1;
 
-t_sensors* sensors = NULL;
-t_fans* fans = NULL;
+t_sensors *sensors = NULL;
+t_fans *fans = NULL;
 
 char *smprintf(const char *fmt, ...)
 {
@@ -105,7 +105,7 @@ bool is_modern_sensors_path()
     char *str_kernel_version;
     str_kernel_version = strtok(kernel.release, ".");
 
-    if (atoi(str_kernel_version) < 3){
+    if (atoi(str_kernel_version) < 3) {
         mbp_log(LOG_ERR, "mbpfan detected a pre-3.x.x linux kernel. Detected version: %s. Exiting.\n", kernel.release);
         exit(EXIT_FAILURE);
     }
@@ -127,7 +127,6 @@ bool is_modern_sensors_path()
     return 0;
 }
 
-
 t_sensors *retrieve_sensors()
 {
     t_sensors *sensors_head = NULL;
@@ -140,7 +139,7 @@ t_sensors *retrieve_sensors()
     int sensors_found = 0;
 
     if (!is_modern_sensors_path()) {
-        if(verbose) {
+        if (verbose) {
             mbp_log(LOG_INFO, "Using legacy path for kernel < 3.15.0");
         }
 
@@ -148,82 +147,82 @@ t_sensors *retrieve_sensors()
 
     } else {
 
-        if(verbose) {
+        if (verbose) {
             mbp_log(LOG_INFO, "Using new sensor path for kernel >= 3.15.0 or some CentOS versions with kernel 3.10.0 ");
         }
 
-	// loop over up to 6 processors
-	int processor;
-	for (processor = 0; processor < NUM_PROCESSORS; processor++) {
+        // loop over up to 6 processors
+        int processor;
+        for (processor = 0; processor < NUM_PROCESSORS; processor++) {
 
-	    if (path_begin != NULL) {
-	        free(path_begin);
-	    }
-	    path_begin = smprintf("/sys/devices/platform/coretemp.%d/hwmon/hwmon", processor);
+            if (path_begin != NULL) {
+                free(path_begin);
+            }
+            path_begin = smprintf("/sys/devices/platform/coretemp.%d/hwmon/hwmon", processor);
 
-	    int counter;
-	    for (counter = 0; counter < NUM_HWMONS; counter++) {
+            int counter;
+            for (counter = 0; counter < NUM_HWMONS; counter++) {
 
                 char *hwmon_path = smprintf("%s%d", path_begin, counter);
 
-		int res = access(hwmon_path, R_OK);
-		if (res == 0) {
+                int res = access(hwmon_path, R_OK);
+                if (res == 0) {
 
-		    free(path_begin);
-		    path_begin = smprintf("%s/temp", hwmon_path);
+                    free(path_begin);
+                    path_begin = smprintf("%s/temp", hwmon_path);
 
-		    if(verbose) {
+                    if (verbose) {
                         mbp_log(LOG_INFO, "Found hwmon path at %s", path_begin);
-		    }
+                    }
 
                     free(hwmon_path);
-		    break;
-		}
+                    break;
+                }
 
                 free(hwmon_path);
-	    }
+            }
 
-	    int core = 0;
-	    for(core = 0; core<NUM_TEMP_INPUTS; core++) {
-		path = smprintf("%s%d%s", path_begin, core, path_end);
+            int core = 0;
+            for (core = 0; core < NUM_TEMP_INPUTS; core++) {
+                path = smprintf("%s%d%s", path_begin, core, path_end);
 
-		FILE *file = fopen(path, "r");
+                FILE *file = fopen(path, "r");
 
-		if(file != NULL) {
-		    s = (t_sensors *) malloc( sizeof( t_sensors ) );
-		    s->path = strdup(path);
-		    fscanf(file, "%d", &s->temperature);
+                if (file != NULL) {
+                    s = (t_sensors *)malloc(sizeof(t_sensors));
+                    s->path = strdup(path);
+                    fscanf(file, "%d", &s->temperature);
 
-		    if (sensors_head == NULL) {
-			sensors_head = s;
-			sensors_head->next = NULL;
+                    if (sensors_head == NULL) {
+                        sensors_head = s;
+                        sensors_head->next = NULL;
 
-		    } else {
-			t_sensors *tmp = sensors_head;
+                    } else {
+                        t_sensors *tmp = sensors_head;
 
-			while (tmp->next != NULL) {
-			    tmp = tmp->next;
-			}
+                        while (tmp->next != NULL) {
+                            tmp = tmp->next;
+                        }
 
-			tmp->next = s;
-			tmp->next->next = NULL;
-		    }
+                        tmp->next = s;
+                        tmp->next->next = NULL;
+                    }
 
-		    s->file = file;
-		    sensors_found++;
-		}
+                    s->file = file;
+                    sensors_found++;
+                }
 
-		free(path);
-		path = NULL;
-	    }
-	}
+                free(path);
+                path = NULL;
+            }
+        }
     }
 
-    if(verbose) {
+    if (verbose) {
         mbp_log(LOG_INFO, "Found %d sensors", sensors_found);
     }
 
-    if (sensors_found == 0){
+    if (sensors_found == 0) {
         mbp_log(LOG_CRIT, "mbpfan could not detect any temp sensor. Please contact the developer.");
         exit(EXIT_FAILURE);
     }
@@ -280,37 +279,37 @@ t_fans *retrieve_fans()
     const char *path_man_end = "_manual";
     const char *path_max_speed = "_max";
     const char *path_min_speed = "_min";
-    
+
     int counter = 0;
     int fans_found = 0;
 
-    for(counter = 0; counter<NUM_FANS; counter++) {
+    for (counter = 0; counter < NUM_FANS; counter++) {
 
         path_output = smprintf("%s%d%s", path_begin, counter, path_output_end);
         path_label = smprintf("%s%d%s", path_begin, counter, path_label_end);
         path_manual = smprintf("%s%d%s", path_begin, counter, path_man_end);
-	path_fan_min = smprintf("%s%d%s",path_begin, counter, path_min_speed);
-	path_fan_max = smprintf("%s%d%s",path_begin, counter, path_max_speed);
+        path_fan_min = smprintf("%s%d%s", path_begin, counter, path_min_speed);
+        path_fan_max = smprintf("%s%d%s", path_begin, counter, path_max_speed);
 
         FILE *file = fopen(path_output, "w");
 
-        if(file != NULL) {
-            fan = (t_fans *) malloc( sizeof( t_fans ) );
+        if (file != NULL) {
+            fan = (t_fans *)malloc(sizeof(t_fans));
             fan->fan_output_path = strdup(path_output);
             fan->fan_manual_path = strdup(path_manual);
-	    fan->fan_id = counter;
+            fan->fan_id = counter;
 
-	    int fan_speed = read_value(path_fan_min);
-	    if(fan_speed == -1 || fan_speed < MIN_FAN_SPEED_DEFAULT)
-		fan->fan_min_speed = MIN_FAN_SPEED_DEFAULT;
-	    else
-		fan->fan_min_speed = fan_speed;
+            int fan_speed = read_value(path_fan_min);
+            if (fan_speed == -1 || fan_speed < MIN_FAN_SPEED_DEFAULT)
+                fan->fan_min_speed = MIN_FAN_SPEED_DEFAULT;
+            else
+                fan->fan_min_speed = fan_speed;
 
-	    fan_speed = read_value(path_fan_max);
-	    if(fan_speed == -1 || fan_speed > MAX_FAN_SPEED_DEFAULT)
-		fan->fan_max_speed = MAX_FAN_SPEED_DEFAULT;
-	    else
-		fan->fan_max_speed = fan_speed;
+            fan_speed = read_value(path_fan_max);
+            if (fan_speed == -1 || fan_speed > MAX_FAN_SPEED_DEFAULT)
+                fan->fan_max_speed = MAX_FAN_SPEED_DEFAULT;
+            else
+                fan->fan_max_speed = fan_speed;
 
             size_t max_label_len = 64;
             fan->label = malloc(max_label_len);
@@ -337,23 +336,23 @@ t_fans *retrieve_fans()
             fan->file = file;
             fans_found++;
         }
-	free(path_fan_min);
-	path_fan_min = NULL;
-	free(path_label);
-	path_label = NULL;
-	free(path_fan_max);
-	path_fan_max = NULL;
+        free(path_fan_min);
+        path_fan_min = NULL;
+        free(path_label);
+        path_label = NULL;
+        free(path_fan_max);
+        path_fan_max = NULL;
         free(path_output);
         path_output = NULL;
         free(path_manual);
         path_manual = NULL;
     }
 
-    if(verbose) {
+    if (verbose) {
         mbp_log(LOG_INFO, "Found %d fans", fans_found);
     }
 
-    if (fans_found == 0){
+    if (fans_found == 0) {
         mbp_log(LOG_CRIT, "mbpfan could not detect any fan. Please contact the developer.");
         exit(EXIT_FAILURE);
     }
@@ -366,10 +365,10 @@ static void set_fans_mode(t_fans *fans, int mode)
     t_fans *tmp = fans;
     FILE *file;
 
-    while(tmp != NULL) {
+    while (tmp != NULL) {
         file = fopen(tmp->fan_manual_path, "rw+");
 
-        if(file != NULL) {
+        if (file != NULL) {
             fprintf(file, "%d", mode);
             fclose(file);
         }
@@ -394,10 +393,10 @@ t_sensors *refresh_sensors(t_sensors *sensors)
 {
     t_sensors *tmp = sensors;
 
-    while(tmp != NULL) {
-        if(tmp->file != NULL) {
+    while (tmp != NULL) {
+        if (tmp->file != NULL) {
             char buf[16];
-            int len = pread(fileno(tmp->file), buf, sizeof(buf), /*offset=*/ 0);
+            int len = pread(fileno(tmp->file), buf, sizeof(buf), /*offset=*/0);
             buf[len] = '\0';
             tmp->temperature = strtod(buf, NULL);
         }
@@ -409,36 +408,36 @@ t_sensors *refresh_sensors(t_sensors *sensors)
 }
 
 /* Controls the speed of a fan */
-void set_fan_speed(t_fans* fan, int speed)
+void set_fan_speed(t_fans *fan, int speed)
 {
-    if(fan != NULL && fan->file != NULL && fan->old_speed != speed) {
-       char buf[16];
-       int len = snprintf(buf, sizeof(buf), "%d", speed);
-       int res = pwrite(fileno(fan->file), buf, len, /*offset=*/ 0);
-       if (res == -1) {
-          perror("Could not set fan speed");
-       }
-       fan->old_speed = speed;
+    if (fan != NULL && fan->file != NULL && fan->old_speed != speed) {
+        char buf[16];
+        int len = snprintf(buf, sizeof(buf), "%d", speed);
+        int res = pwrite(fileno(fan->file), buf, len, /*offset=*/0);
+        if (res == -1) {
+            perror("Could not set fan speed");
+        }
+        fan->old_speed = speed;
     }
 }
 
-void set_fan_minimum_speed(t_fans* fans)
+void set_fan_minimum_speed(t_fans *fans)
 {
-   t_fans *tmp = fans;
+    t_fans *tmp = fans;
 
-   while(tmp != NULL) {
-      set_fan_speed(tmp,tmp->fan_min_speed); 
-      tmp = tmp->next;
-   }
+    while (tmp != NULL) {
+        set_fan_speed(tmp, tmp->fan_min_speed);
+        tmp = tmp->next;
+    }
 }
-unsigned short get_temp(t_sensors* sensors)
+unsigned short get_temp(t_sensors *sensors)
 {
     sensors = refresh_sensors(sensors);
     unsigned int temp = 0;
 
-    t_sensors* tmp = sensors;
+    t_sensors *tmp = sensors;
 
-    while(tmp != NULL) {
+    while (tmp != NULL) {
         temp = max(temp, tmp->temperature);
         tmp = tmp->next;
     }
@@ -446,7 +445,7 @@ unsigned short get_temp(t_sensors* sensors)
     return temp / 1000;
 }
 
-void retrieve_settings(const char* settings_path, t_fans* fans)
+void retrieve_settings(const char *settings_path, t_fans *fans)
 {
     Settings *settings = NULL;
     int result = 0;
@@ -459,10 +458,9 @@ void retrieve_settings(const char* settings_path, t_fans* fans)
         f = fopen(settings_path, "r");
     }
 
-
     if (f == NULL) {
         /* Could not open configfile */
-        if(verbose) {
+        if (verbose) {
             mbp_log(LOG_INFO, "Couldn't open configfile, using defaults");
         }
 
@@ -472,34 +470,34 @@ void retrieve_settings(const char* settings_path, t_fans* fans)
 
         if (settings == NULL) {
             /* Could not read configfile */
-            if(verbose) {
+            if (verbose) {
                 mbp_log(LOG_WARNING, "Couldn't read configfile");
             }
 
         } else {
-	
-	    t_fans *fan = fans;
 
-	    while(fan != NULL) {
+            t_fans *fan = fans;
 
-		char* config_key;
-		config_key = smprintf("min_fan%d_speed", fan->fan_id);
+            while (fan != NULL) {
+
+                char *config_key;
+                config_key = smprintf("min_fan%d_speed", fan->fan_id);
                 /* Read configfile values */
                 result = settings_get_int(settings, "general", config_key);
                 if (result != 0) {
-                   fan->fan_min_speed = result;
+                    fan->fan_min_speed = result;
                 }
-		free(config_key);
-		
-		config_key = smprintf("max_fan%d_speed", fan->fan_id);
+                free(config_key);
+
+                config_key = smprintf("max_fan%d_speed", fan->fan_id);
                 result = settings_get_int(settings, "general", config_key);
 
                 if (result != 0) {
-                   fan->fan_max_speed = result;
+                    fan->fan_max_speed = result;
                 }
-		free(config_key);
-		fan = fan->next;
-	    }
+                free(config_key);
+                fan = fan->next;
+            }
             result = settings_get_int(settings, "general", "low_temp");
 
             if (result != 0) {
@@ -530,14 +528,14 @@ void retrieve_settings(const char* settings_path, t_fans* fans)
     }
 }
 
-void check_requirements(const char* program_path)
+void check_requirements(const char *program_path)
 {
 
     /**
      * Check for root
      */
 
-    uid_t uid=getuid(), euid=geteuid();
+    uid_t uid = getuid(), euid = geteuid();
 
     if (uid != 0 || euid != 0) {
         mbp_log(LOG_ERR, "%s needs root privileges. Please run %s as root. Exiting.", program_path, program_path);
@@ -545,9 +543,9 @@ void check_requirements(const char* program_path)
     }
 
     /**
-      * Check for coretemp and applesmc modules
-      */
-    DIR* dir = opendir(CORETEMP_PATH);
+     * Check for coretemp and applesmc modules
+     */
+    DIR *dir = opendir(CORETEMP_PATH);
 
     if (ENOENT == errno) {
         mbp_log(LOG_ERR, "%s needs coretemp support. Please either load it or build it into the kernel. Exiting.", program_path);
@@ -556,7 +554,6 @@ void check_requirements(const char* program_path)
 
     closedir(dir);
 
-
     dir = opendir(APPLESMC_PATH);
 
     if (ENOENT == errno) {
@@ -565,8 +562,6 @@ void check_requirements(const char* program_path)
     }
 
     closedir(dir);
-
-
 }
 
 int get_max_mhz(void)
@@ -578,9 +573,7 @@ int get_max_mhz(void)
     }
     struct dirent *ent;
     while ((ent = readdir(dir)) != NULL) {
-        if (strncmp(ent->d_name, "cpu", 3) != 0 ||
-            strcmp(ent->d_name, "cpufreq") == 0 ||
-            strcmp(ent->d_name, "cpuidle") == 0) {
+        if (strncmp(ent->d_name, "cpu", 3) != 0 || strcmp(ent->d_name, "cpufreq") == 0 || strcmp(ent->d_name, "cpuidle") == 0) {
             continue;
         }
         char *path = smprintf("/sys/devices/system/cpu/%s/cpufreq/scaling_cur_freq", ent->d_name);
@@ -595,20 +588,20 @@ void mbpfan()
 {
     int old_temp, new_temp, fan_speed, steps;
     int temp_change;
-    
+
     sensors = retrieve_sensors();
     fans = retrieve_fans();
 
     retrieve_settings(NULL, fans);
-    
-    t_fans* fan = fans;
-    while(fan != NULL) {
-	
+
+    t_fans *fan = fans;
+    while (fan != NULL) {
+
         if (fan->fan_min_speed > fan->fan_max_speed) {
-            mbp_log(LOG_ERR, "Invalid fan speeds: %d %d", fan->fan_min_speed,  fan->fan_max_speed);
+            mbp_log(LOG_ERR, "Invalid fan speeds: %d %d", fan->fan_min_speed, fan->fan_max_speed);
             exit(EXIT_FAILURE);
         }
-	fan = fan->next;
+        fan = fan->next;
     }
 
     if (low_temp > high_temp || high_temp > max_temp) {
@@ -622,63 +615,61 @@ void mbpfan()
     set_fan_minimum_speed(fans);
 
     fan = fans;
-    while(fan != NULL) {
+    while (fan != NULL) {
 
-       fan->step_up = (float)( fan->fan_max_speed - fan->fan_min_speed ) /
-                      (float)( ( max_temp - high_temp ) * ( max_temp - high_temp + 1 ) / 2.0 );
+        fan->step_up = (float)(fan->fan_max_speed - fan->fan_min_speed) / (float)((max_temp - high_temp) * (max_temp - high_temp + 1) / 2.0);
 
-       fan->step_down = (float)( fan->fan_max_speed - fan->fan_min_speed ) /
-                        (float)( ( max_temp - low_temp ) * ( max_temp - low_temp + 1 ) / 2.0 );
-       fan = fan->next;
+        fan->step_down = (float)(fan->fan_max_speed - fan->fan_min_speed) / (float)((max_temp - low_temp) * (max_temp - low_temp + 1) / 2.0);
+        fan = fan->next;
     }
 
 recalibrate:
-    if(verbose) {
+    if (verbose) {
         mbp_log(LOG_INFO, "Sleeping for 2 seconds to get first temp delta");
     }
     sleep(2);
 
-    while(1) {
+    while (1) {
         old_temp = new_temp;
         new_temp = get_temp(sensors);
 
         fan = fans;
 
-	while(fan != NULL) {
-	    fan_speed = fan->old_speed;
+        while (fan != NULL) {
+            fan_speed = fan->old_speed;
 
-	    if(new_temp >= max_temp && fan->old_speed != fan->fan_max_speed) {
+            if (new_temp >= max_temp && fan->old_speed != fan->fan_max_speed) {
                 fan_speed = fan->fan_max_speed;
             }
 
-            if(new_temp <= low_temp && fan_speed != fan->fan_min_speed) {
+            if (new_temp <= low_temp && fan_speed != fan->fan_min_speed) {
                 fan_speed = fan->fan_min_speed;
             }
 
             temp_change = new_temp - old_temp;
 
-            if(temp_change > 0 && new_temp > high_temp && new_temp < max_temp) {
-                steps = ( new_temp - high_temp ) * ( new_temp - high_temp + 1 ) / 2;
-                fan_speed = max( fan_speed, ceil(fan->fan_min_speed + steps * fan->step_up) );
+            if (temp_change > 0 && new_temp > high_temp && new_temp < max_temp) {
+                steps = (new_temp - high_temp) * (new_temp - high_temp + 1) / 2;
+                fan_speed = max(fan_speed, ceil(fan->fan_min_speed + steps * fan->step_up));
             }
 
-            if(temp_change < 0 && new_temp > low_temp && new_temp < max_temp) {
-                steps = ( max_temp - new_temp ) * ( max_temp - new_temp + 1 ) / 2;
-                fan_speed = min( fan_speed, floor(fan->fan_max_speed - steps * fan->step_down) );
+            if (temp_change < 0 && new_temp > low_temp && new_temp < max_temp) {
+                steps = (max_temp - new_temp) * (max_temp - new_temp + 1) / 2;
+                fan_speed = min(fan_speed, floor(fan->fan_max_speed - steps * fan->step_down));
             }
 
-            if(verbose) {
+            if (verbose) {
                 mbp_log(LOG_INFO, "Old Temp: %d New Temp: %d Fan: %s Speed: %d Max MHz: %d", old_temp, new_temp, fan->label, fan_speed, get_max_mhz());
-	    }
+            }
 
-	    set_fan_speed(fan, fan_speed);
-       	    fan = fan->next;
-	} 
+            set_fan_speed(fan, fan_speed);
+            fan = fan->next;
+        }
 
-        if(verbose) {
+        if (verbose) {
             mbp_log(LOG_INFO, "Sleeping for %d seconds", polling_interval);
         }
-   
+
         time_t before_sleep = time(NULL);
 
         // call nanosleep instead of sleep to avoid rt_sigprocmask and
@@ -689,7 +680,7 @@ recalibrate:
         nanosleep(&ts, NULL);
 
         time_t after_sleep = time(NULL);
-        if(after_sleep - before_sleep > 2 * polling_interval) {
+        if (after_sleep - before_sleep > 2 * polling_interval) {
             mbp_log(LOG_INFO, "Clock skew detected - slept for %ld seconds but expected %d", after_sleep - before_sleep, polling_interval);
             set_fans_man(fans);
             goto recalibrate;
diff --git a/src/mbpfan.h b/src/mbpfan.h
index f673a58..d93c6d2 100644
--- a/src/mbpfan.h
+++ b/src/mbpfan.h
@@ -40,7 +40,7 @@ typedef struct s_sensors t_sensors;
 struct s_fans;
 typedef struct s_fans t_fans;
 
-char *smprintf(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
+char *smprintf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 
 /**
  * Return true if the kernel is < 3.15.0
@@ -52,7 +52,7 @@ bool is_legacy_sensors_path();
  * /etc/mbpfan.conf
  * If it fails, the default hardcoded settings are used
  */
-void retrieve_settings(const char* settings_path, t_fans *fans);
+void retrieve_settings(const char *settings_path, t_fans *fans);
 
 /**
  * Detect the sensors in /sys/devices/platform/coretemp.0/temp
@@ -71,7 +71,7 @@ t_sensors *refresh_sensors(t_sensors *sensors);
  * Detect the fans in /sys/devices/platform/applesmc.768/
  * Associate each fan to a sensor
  */
-t_fans* retrieve_fans();
+t_fans *retrieve_fans();
 
 /**
  * Given a list of sensors with associated fans
@@ -89,22 +89,22 @@ void set_fans_auto(t_fans *fans);
  * Given a sensors with associated fans
  * Change their speed
  */
-void set_fan_speed(t_fans* fan, int speed);
+void set_fan_speed(t_fans *fan, int speed);
 
 /**
  * Given a list of fans set their minumum fan speed
  */
-void set_fan_minimum_speed(t_fans* fans);
+void set_fan_minimum_speed(t_fans *fans);
 /**
  *  Return maximum CPU temp in degrees
  */
-unsigned short get_temp(t_sensors* sensors);
+unsigned short get_temp(t_sensors *sensors);
 
 /**
  * Check if user has proper access and that required
  * kernel modules are available
  */
-void check_requirements(const char* program_path);
+void check_requirements(const char *program_path);
 
 /**
  * Main Program
diff --git a/src/settings.c b/src/settings.c
index 20d18f3..32bdfb6 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -36,17 +36,17 @@
  */
 #include "settings.h"
 
-#define MAX_SECTIONCHARS	256
-#define MAX_KEYCHARS	256
-#define MAX_VALUECHARS	256
-#define MAX_LINECHARS	(MAX_KEYCHARS + MAX_VALUECHARS + 10)
+#define MAX_SECTIONCHARS 256
+#define MAX_KEYCHARS 256
+#define MAX_VALUECHARS 256
+#define MAX_LINECHARS (MAX_KEYCHARS + MAX_VALUECHARS + 10)
 
-#define COMMENT_CHAR	'#'
-#define SECTION_START_CHAR	'['
-#define SECTION_END_CHAR	']'
-#define KEY_VALUE_SEPARATOR_CHAR	'='
+#define COMMENT_CHAR '#'
+#define SECTION_START_CHAR '['
+#define SECTION_END_CHAR ']'
+#define KEY_VALUE_SEPARATOR_CHAR '='
 
-#define DEFAULT_STRMAP_CAPACITY	256
+#define DEFAULT_STRMAP_CAPACITY 256
 
 typedef struct Section Section;
 typedef struct ParseState ParseState;
@@ -83,20 +83,20 @@ static int is_comment_str(const char *str);
 static int is_section_str(const char *str);
 static int is_key_value_str(const char *str);
 static int is_key_without_value_str(const char *str);
-static const char * get_token(char *str, char delim, char **last);
+static const char *get_token(char *str, char delim, char **last);
 static int get_section_from_str(const char *str, char *out_buf, unsigned int out_buf_n);
 static int get_key_value_from_str(const char *str, char *out_buf1, unsigned int out_buf1_n, char *out_buf2, unsigned int out_buf2_n);
 static int get_key_without_value_from_str(const char *str, char *out_buf, unsigned int out_buf_n);
 static int get_converted_value(const Settings *settings, const char *section, const char *key, ConvertMode mode, void *out);
 static int get_converted_tuple(const Settings *settings, const char *section, const char *key, char delim, ConvertMode mode, void *out, unsigned int n_out);
-static Section * get_section(Section *sections, unsigned int n, const char *name);
+static Section *get_section(Section *sections, unsigned int n, const char *name);
 static void enum_map(const char *key, const char *value, const void *obj);
 
-Settings * settings_new()
+Settings *settings_new()
 {
     Settings *settings;
 
-    settings = (Settings*)malloc(sizeof(Settings));
+    settings = (Settings *)malloc(sizeof(Settings));
 
     if (settings == NULL) {
         return NULL;
@@ -135,7 +135,7 @@ void settings_delete(Settings *settings)
     free(settings);
 }
 
-Settings * settings_open(FILE *stream)
+Settings *settings_open(FILE *stream)
 {
     Settings *settings;
     char buf[MAX_LINECHARS];
@@ -285,7 +285,7 @@ int settings_set(Settings *settings, const char *section, const char *key, const
 
     if (s == NULL) {
         /* The section is not created---create it */
-        s = (Section*)realloc(settings->sections, (settings->section_count + 1) * sizeof(Section));
+        s = (Section *)realloc(settings->sections, (settings->section_count + 1) * sizeof(Section));
 
         if (s == NULL) {
             return 0;
@@ -301,7 +301,7 @@ int settings_set(Settings *settings, const char *section, const char *key, const
             return 0;
         }
 
-        s->name = (char*)malloc((strlen(section) + 1) * sizeof(char));
+        s->name = (char *)malloc((strlen(section) + 1) * sizeof(char));
 
         if (s->name == NULL) {
             sm_delete(s->map);
@@ -723,7 +723,7 @@ static int get_key_without_value_from_str(const char *str, char *out_buf, unsign
  *     printf("token: %s", token);
  * }
  */
-static const char * get_token(char *str, char delim, char **last)
+static const char *get_token(char *str, char delim, char **last)
 {
 
     char *s0;
@@ -845,7 +845,7 @@ static int get_converted_tuple(const Settings *settings, const char *section, co
 /* Returns a pointer to the section or null if the named section does not
  * exist.
  */
-static Section * get_section(Section *sections, unsigned int n, const char *name)
+static Section *get_section(Section *sections, unsigned int n, const char *name)
 {
     unsigned int i;
     Section *section;
@@ -896,7 +896,7 @@ static void enum_map(const char *key, const char *value, const void *obj)
 
 /*
 
-		   GNU LESSER GENERAL PUBLIC LICENSE
+                   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
diff --git a/src/settings.h b/src/settings.h
index 4b3ada8..1698f9b 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -39,8 +39,7 @@
 #include "strmap.h"
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 typedef struct Settings Settings;
@@ -62,7 +61,7 @@ typedef struct Settings Settings;
  *
  * Return value: None.
  */
-typedef void(*settings_section_enum_func)(const char *key, const char *value, const void *obj);
+typedef void (*settings_section_enum_func)(const char *key, const char *value, const void *obj);
 
 /*
  * Creates a settings object.
@@ -70,7 +69,7 @@ typedef void(*settings_section_enum_func)(const char *key, const char *value, co
  * Return value: A pointer to a settings object,
  * or null if a new settings object could not be allocated.
  */
-Settings * settings_new();
+Settings *settings_new();
 
 /*
  * Releases all memory held by a settings object.
@@ -98,7 +97,7 @@ void settings_delete(Settings *settings);
  * Return value: A pointer to a settings object,
  * or null if an error occurred.
  */
-Settings * settings_open(FILE *stream);
+Settings *settings_open(FILE *stream);
 
 /*
  * Saves the current settings object in textual form to the given stream.
@@ -338,7 +337,7 @@ int settings_section_enum(const Settings *settings, const char *section, setting
 
 /*
 
-		   GNU LESSER GENERAL PUBLIC LICENSE
+                   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
diff --git a/src/strmap.c b/src/strmap.c
index 45853e3..cdbe6ff 100644
--- a/src/strmap.c
+++ b/src/strmap.c
@@ -54,21 +54,21 @@ struct StrMap {
     Bucket *buckets;
 };
 
-static Pair * get_pair(Bucket *bucket, const char *key);
+static Pair *get_pair(Bucket *bucket, const char *key);
 static unsigned long hash(const char *str);
 
-StrMap * sm_new(unsigned int capacity)
+StrMap *sm_new(unsigned int capacity)
 {
     StrMap *map;
 
-    map = (StrMap*)malloc(sizeof(StrMap));
+    map = (StrMap *)malloc(sizeof(StrMap));
 
     if (map == NULL) {
         return NULL;
     }
 
     map->count = capacity;
-    map->buckets = (Bucket*)malloc(map->count * sizeof(Bucket));
+    map->buckets = (Bucket *)malloc(map->count * sizeof(Bucket));
 
     if (map->buckets == NULL) {
         free(map);
@@ -98,7 +98,7 @@ void sm_delete(StrMap *map)
         pair = bucket->pairs;
         j = 0;
 
-        while(j < m) {
+        while (j < m) {
             free(pair->key);
             free(pair->value);
             pair++;
@@ -210,7 +210,7 @@ int sm_put(StrMap *map, const char *key, const char *value)
             /* If the new value is larger than the old value, re-allocate
              * space for the new larger value.
              */
-            tmp_value = (char*)realloc(pair->value, (value_len + 1) * sizeof(char));
+            tmp_value = (char *)realloc(pair->value, (value_len + 1) * sizeof(char));
 
             if (tmp_value == NULL) {
                 return 0;
@@ -225,13 +225,13 @@ int sm_put(StrMap *map, const char *key, const char *value)
     }
 
     /* Allocate space for a new key and value */
-    new_key = (char*)malloc((key_len + 1) * sizeof(char));
+    new_key = (char *)malloc((key_len + 1) * sizeof(char));
 
     if (new_key == NULL) {
         return 0;
     }
 
-    new_value = (char*)malloc((value_len + 1) * sizeof(char));
+    new_value = (char *)malloc((value_len + 1) * sizeof(char));
 
     if (new_value == NULL) {
         free(new_key);
@@ -243,7 +243,7 @@ int sm_put(StrMap *map, const char *key, const char *value)
         /* The bucket is empty, lazily allocate space for a single
          * key-value pair.
          */
-        bucket->pairs = (Pair*)malloc(sizeof(Pair));
+        bucket->pairs = (Pair *)malloc(sizeof(Pair));
 
         if (bucket->pairs == NULL) {
             free(new_key);
@@ -257,7 +257,7 @@ int sm_put(StrMap *map, const char *key, const char *value)
         /* The bucket wasn't empty but no pair existed that matches the provided
          * key, so create a new key-value pair.
          */
-        tmp_pairs = (Pair*)realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));
+        tmp_pairs = (Pair *)realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));
 
         if (tmp_pairs == NULL) {
             free(new_key);
@@ -353,7 +353,7 @@ int sm_enum(const StrMap *map, sm_enum_func enum_func, const void *obj)
  * Returns a pair from the bucket that matches the provided key,
  * or null if no such pair exist.
  */
-static Pair * get_pair(Bucket *bucket, const char *key)
+static Pair *get_pair(Bucket *bucket, const char *key)
 {
     unsigned int i, n;
     Pair *pair;
@@ -398,7 +398,7 @@ static unsigned long hash(const char *str)
 
 /*
 
-		   GNU LESSER GENERAL PUBLIC LICENSE
+                   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
diff --git a/src/strmap.h b/src/strmap.h
index 416a1ce..5206cbb 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -37,8 +37,7 @@
 #define _STRMAP_H_
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
 #include <stdlib.h>
@@ -63,7 +62,7 @@ typedef struct StrMap StrMap;
  *
  * Return value: None.
  */
-typedef void(*sm_enum_func)(const char *key, const char *value, const void *obj);
+typedef void (*sm_enum_func)(const char *key, const char *value, const void *obj);
 
 /*
  * Creates a string map.
@@ -76,7 +75,7 @@ typedef void(*sm_enum_func)(const char *key, const char *value, const void *obj)
  * Return value: A pointer to a string map object,
  * or null if a new string map could not be allocated.
  */
-StrMap * sm_new(unsigned int capacity);
+StrMap *sm_new(unsigned int capacity);
 
 /*
  * Releases all memory held by a string map object.
@@ -186,7 +185,7 @@ int sm_enum(const StrMap *map, sm_enum_func enum_func, const void *obj);
 
 /*
 
-		   GNU LESSER GENERAL PUBLIC LICENSE
+                   GNU LESSER GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
diff --git a/src/util.c b/src/util.c
index 136bcc6..c66e6d7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -16,6 +16,6 @@ void mbp_log(int level, const char *fmt, ...)
 
     va_start(args, fmt);
     vprintf(fmt, args);
-    puts("");  // trailing newline
+    puts(""); // trailing newline
     va_end(args);
 }
diff --git a/src/util.h b/src/util.h
index 9bf99ce..7f4a280 100644
--- a/src/util.h
+++ b/src/util.h
@@ -1,6 +1,6 @@
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
-void mbp_log(int level, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
+void mbp_log(int level, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
 
 #endif