thermal: pwm-fan: lock during sysfs writes
Anshul Jain [Wed, 16 Oct 2013 03:18:57 +0000 (20:18 -0700)]
This change locks the whole sysfs function to ensure
atomicity. Also, more logs are added for better visibility
during suspend and resume.

Bug 1388303

Change-Id: Iadf8bdc4309575ec42a1946ecfb28eb7654440e3
Signed-off-by: Anshul Jain <anshulj@nvidia.com>
Reviewed-on: http://git-master/r/299756
(cherry picked from commit 5eec7cd755f9c8dbdc826d63f10b30cad237eb5d)
Reviewed-on: http://git-master/r/347142
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

drivers/thermal/pwm_fan.c

index dcc3697..5fb1c5d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * pwm_fan.c fan driver that is controlled by pwm
  *
- * Copyright (c) 2012-2013 NVIDIA CORPORATION, All rights reserved.
+ * Copyright (c) 2013-2014, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Anshul Jain <anshulj@nvidia.com>
  *
@@ -556,28 +556,26 @@ static ssize_t set_fan_state_cap_sysfs(struct device *dev,
 
        ret = kstrtol(buf, 10, &val);
 
-       if (ret < 0)
-               return -EINVAL;
-
-       if (!fan_data)
-               return -EINVAL;
+       if (ret < 0 || !fan_data)
+               goto error;
 
+       mutex_lock(&fan_data->fan_state_lock);
        if (val < 0)
                val = 0;
        else if (val >= fan_data->active_steps)
                val = fan_data->active_steps - 1;
 
-       mutex_lock(&fan_data->fan_state_lock);
        fan_data->fan_state_cap = val;
        fan_data->fan_cap_pwm =
                fan_data->fan_pwm[fan_data->fan_state_cap_lookup[val]];
        fan_data->next_target_pwm = min(fan_data->fan_cap_pwm,
                                        fan_data->next_target_pwm);
-       dev_info(dev, "pwm_cap=%d target_pwm=%d\n",
-               fan_data->fan_cap_pwm, fan_data->next_target_pwm);
-
        mutex_unlock(&fan_data->fan_state_lock);
        return count;
+
+error:
+       dev_err(dev, "%s, fan_data is null or wrong input\n", __func__);
+       return -EINVAL;
 }
 
 
@@ -860,9 +858,6 @@ static int pwm_fan_resume(struct platform_device *pdev)
        /*Sanity check, want to make sure fan is off when the driver resumes*/
        mutex_lock(&fan_data->fan_state_lock);
 
-       dev_info(&pdev->dev, "%s, cur_pwm:%d, target_pwm:%d, cap:%d",
-       __func__, fan_data->fan_cur_pwm, fan_data->next_target_pwm,
-       fan_data->fan_cap_pwm);
        gpio_free(fan_data->pwm_gpio);
        fan_data->pwm_dev = pwm_request(fan_data->pwm_id, dev_name(&pdev->dev));
        if (IS_ERR_OR_NULL(fan_data->pwm_dev)) {