Skip to contentSkip to conversation

pwm: Declare local variables as such

PATCH New Jean Delvare 1 participant 1 message Apr 28, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 5/5 pwm: Declare local variables as such

Declare local variables as such to avoid unintended side effects.

---
 prog/pwm/fancontrol |   27 +++++++++++++++++++--------
 prog/pwm/pwmconfig  |   22 ++++++++++++++--------
 2 files changed, 33 insertions(+), 16 deletions(-)
prog/pwm/fancontrol +19 -8
@@ -43,9 +43,10 @@ PIDFILE="/var/run/fancontrol.pid"
 #DEBUG=1
 MAX%5
 
-declare -i pwmval
+function LoadConfig
+{
+	local fcvcount fcv
 
-function LoadConfig {
 	echo "Loading configuration from $1 ..."
 	if [ ! -r "$1" ]
 	then
@@ -206,8 +207,9 @@ function ValidateDevices()
 }
 
 # Check that all referenced sysfs files exist
-function CheckFiles {
-	local outdated=0
+function CheckFiles
+{
+	local outdated=0 fcvcount pwmo tsen fan
 
 	let fcvcount=0
 	while (( $fcvcount < ${#AFCPWM[@]} )) # go through all pwm outputs
@@ -311,7 +313,8 @@ echo $$ > "$PIDFILE"
 # $1 = pwm file name
 function pwmdisable()
 {
-	ENABLE=${1}_enable
+	local ENABLE=${1}_enable
+
 	# No enable file? Just set to max
 	if [ ! -f $ENABLE ]
 	then
@@ -344,7 +347,8 @@ function pwmdisable()
 # $1 = pwm file name
 function pwmenable()
 {
-	ENABLE=${1}_enable
+	local ENABLE=${1}_enable
+
 	if [ -f $ENABLE ]
 	then
 		echo 1 > $ENABLE 2> /dev/null
@@ -358,7 +362,8 @@ function pwmenable()
 
 function restorefans()
 {
-	local status=$1
+	local status=$1 fcvcount pwmo
+
 	echo 'Aborting, restoring fans...'
 	let fcvcount=0
 	while (( $fcvcount < ${#AFCPWM[@]} )) # go through all pwm outputs
@@ -376,7 +381,13 @@ trap 'restorefans 0' SIGQUIT SIGTERM
 trap 'restorefans 1' SIGHUP SIGINT
 
 # main function
-function UpdateFanSpeeds {
+function UpdateFanSpeeds
+{
+	local fcvcount
+	local pwmo tsens fan mint maxt minsa minso minpwm maxpwm
+	local tval pwmpval fanval min_fanval one_fan one_fanval
+	local -i pwmval
+
 	let fcvcount=0
 	while (( $fcvcount < ${#AFCPWM[@]} )) # go through all pwm outputs
 	do
prog/pwm/pwmconfig +13 -8
@@ -144,7 +144,7 @@ fi
 # $1 = padding
 function print_devices()
 {
-	local name
+	local name device
 
 	for device in $DEVICES
 	do
@@ -157,7 +157,8 @@ function print_devices()
 # $1 = pwm file name
 function is_pwm_auto()
 {
-	ENABLE=${1}_enable
+	local ENABLE=${1}_enable
+
 	if [ -f $ENABLE ]
 	then
 		if [ "`cat $ENABLE`" -gt 1 ]
@@ -172,7 +173,8 @@ function is_pwm_auto()
 # $1 = pwm file name
 function pwmdisable()
 {
-	ENABLE=${1}_enable
+	local ENABLE=${1}_enable
+
 	# No enable file? Just set to max
 	if [ ! -f $ENABLE ]
 	then
@@ -211,7 +213,8 @@ function pwmdisable()
 # $1 = pwm file name
 function pwmenable()
 {
-	ENABLE=${1}_enable
+	local ENABLE=${1}_enable
+
 	if [ -w $ENABLE ]
 	then
 		echo 1 2>/dev/null > $ENABLE
@@ -326,9 +329,9 @@ STEP2_BELOW1
 
 function pwmdetail()
 {
-	P=$1
-	F=$2
-	PLOT+	local P=$1 F=$2
+	local X PLOT= TMP1 TMP2
+	local threshold0000 pwm S
 
 	type $PLOTTER > /dev/null 2>&1
 	if [ $? -eq 0 ]
@@ -359,7 +362,6 @@ function pwmdetail()
 		> $TMP2
 	fi
 
-	local threshold0000
 	let pwm=$MAX
 	pwmenable $P
 	while [ $pwm -ge 0 ]
@@ -666,6 +668,8 @@ LoadConfig $FCCONFIG
 # $1 = pwm value below which the fan is stopped
 function TestMinStart()
 {
+	local fanok FANTEST
+
 	echo
 	echo 'Now we increase the PWM value in 10-unit-steps.'
 	echo 'Let the fan stop completely, then press return until the'
@@ -791,6 +795,8 @@ function RememberDevices()
 
 function SaveConfig()
 {
+	local tmpfile
+
 	RememberDevices "$FCTEMPS" "$FCFANS"
 
 	echo
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors