diff mbox

[1/1] toshiba_acpi: Add set_fan_status function

Message ID 1437615474-27936-3-git-send-email-coproscefalo@gmail.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Azael Avalos July 23, 2015, 1:37 a.m. UTC
This patch adds a new function named "set_fan_status" to complement
its get* counterpart, as well as to avoid code duplication between
"fan_proc_write" and "fan_store".

Signed-off-by: Azael Avalos <coproscefalo@gmail.com>
---
 drivers/platform/x86/toshiba_acpi.c | 55 ++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 19 deletions(-)

Comments

Darren Hart July 24, 2015, 10:45 p.m. UTC | #1
On Wed, Jul 22, 2015 at 07:37:48PM -0600, Azael Avalos wrote:
> This patch adds a new function named "set_fan_status" to complement
> its get* counterpart, as well as to avoid code duplication between
> "fan_proc_write" and "fan_store".

It also appears to change the error codes returned via sysfs?

Also adds some pr_ statements.

> 
> Signed-off-by: Azael Avalos <coproscefalo@gmail.com>
> ---
>  drivers/platform/x86/toshiba_acpi.c | 55 ++++++++++++++++++++++++-------------
>  1 file changed, 36 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
> index 6013a11..08fc867 100644
> --- a/drivers/platform/x86/toshiba_acpi.c
> +++ b/drivers/platform/x86/toshiba_acpi.c
> @@ -1422,12 +1422,33 @@ static const struct file_operations video_proc_fops = {
>  	.write		= video_proc_write,
>  };
>  
> +/* Fan status */
>  static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
>  {
> -	u32 hci_result;
> +	u32 result = hci_read(dev, HCI_FAN, status);
>  
> -	hci_result = hci_read(dev, HCI_FAN, status);
> -	return hci_result == TOS_SUCCESS ? 0 : -EIO;
> +	if (result == TOS_FAILURE)
> +		pr_err("ACPI call to get Fan status failed\n");

s/Fan/fan/

Below too.

> +	else if (result == TOS_NOT_SUPPORTED)
> +		return -ENODEV;

This condition would have returned -EIO previously correct?

I agree this new one is the right change, but it does pose a risk to userspace.
There is a slim chance we will have to revert if someone complains and can't
work around it, so we need to be clear about this in the commit message at the
very least.
Azael Avalos July 24, 2015, 11:40 p.m. UTC | #2
Hi Darren,

2015-07-24 16:45 GMT-06:00 Darren Hart <dvhart@infradead.org>:
> On Wed, Jul 22, 2015 at 07:37:48PM -0600, Azael Avalos wrote:
>> This patch adds a new function named "set_fan_status" to complement
>> its get* counterpart, as well as to avoid code duplication between
>> "fan_proc_write" and "fan_store".
>
> It also appears to change the error codes returned via sysfs?
>
> Also adds some pr_ statements.
>
>>
>> Signed-off-by: Azael Avalos <coproscefalo@gmail.com>
>> ---
>>  drivers/platform/x86/toshiba_acpi.c | 55 ++++++++++++++++++++++++-------------
>>  1 file changed, 36 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
>> index 6013a11..08fc867 100644
>> --- a/drivers/platform/x86/toshiba_acpi.c
>> +++ b/drivers/platform/x86/toshiba_acpi.c
>> @@ -1422,12 +1422,33 @@ static const struct file_operations video_proc_fops = {
>>       .write          = video_proc_write,
>>  };
>>
>> +/* Fan status */
>>  static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
>>  {
>> -     u32 hci_result;
>> +     u32 result = hci_read(dev, HCI_FAN, status);
>>
>> -     hci_result = hci_read(dev, HCI_FAN, status);
>> -     return hci_result == TOS_SUCCESS ? 0 : -EIO;
>> +     if (result == TOS_FAILURE)
>> +             pr_err("ACPI call to get Fan status failed\n");
>
> s/Fan/fan/
>
> Below too.
>
>> +     else if (result == TOS_NOT_SUPPORTED)
>> +             return -ENODEV;
>
> This condition would have returned -EIO previously correct?

Yes, we were returning -EIO for all error codes, with this patch we are at
least informing userspace that such feature is not supported with
-ENODEV instead of just returnning -EIO all the time.

With the pr_ message we are informing that an ACPI error happened,
which might (or might not) be the drivers fault, and this will be
on par with the rest of the HCI/SCI functions of the driver.

>
> I agree this new one is the right change, but it does pose a risk to userspace.
> There is a slim chance we will have to revert if someone complains and can't
> work around it, so we need to be clear about this in the commit message at the
> very least.

Ok, I spotted a few "issues" on the latter patches, I'll wait for your comments
and send a v2 afterwards with an expanded commit message.

> --
> Darren Hart
> Intel Open Source Technology Center


Cheers
Azael
diff mbox

Patch

diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 6013a11..08fc867 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1422,12 +1422,33 @@  static const struct file_operations video_proc_fops = {
 	.write		= video_proc_write,
 };
 
+/* Fan status */
 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
 {
-	u32 hci_result;
+	u32 result = hci_read(dev, HCI_FAN, status);
 
-	hci_result = hci_read(dev, HCI_FAN, status);
-	return hci_result == TOS_SUCCESS ? 0 : -EIO;
+	if (result == TOS_FAILURE)
+		pr_err("ACPI call to get Fan status failed\n");
+	else if (result == TOS_NOT_SUPPORTED)
+		return -ENODEV;
+	else if (result == TOS_SUCCESS)
+		return 0;
+
+	return -EIO;
+}
+
+static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
+{
+	u32 result = hci_write(dev, HCI_FAN, status);
+
+	if (result == TOS_FAILURE)
+		pr_err("ACPI call to set Fan status failed\n");
+	else if (result == TOS_NOT_SUPPORTED)
+		return -ENODEV;
+	else if (result == TOS_SUCCESS)
+		return 0;
+
+	return -EIO;
 }
 
 static int fan_proc_show(struct seq_file *m, void *v)
@@ -1457,23 +1478,22 @@  static ssize_t fan_proc_write(struct file *file, const char __user *buf,
 	char cmd[42];
 	size_t len;
 	int value;
-	u32 hci_result;
+	int ret;
 
 	len = min(count, sizeof(cmd) - 1);
 	if (copy_from_user(cmd, buf, len))
 		return -EFAULT;
 	cmd[len] = '\0';
 
-	if (sscanf(cmd, " force_on : %i", &value) == 1 &&
-	    value >= 0 && value <= 1) {
-		hci_result = hci_write(dev, HCI_FAN, value);
-		if (hci_result == TOS_SUCCESS)
-			dev->force_fan = value;
-		else
-			return -EIO;
-	} else {
+	if (sscanf(cmd, " force_on : %i", &value) != 1 &&
+	    value != 0 && value != 1)
 		return -EINVAL;
-	}
+
+	ret = set_fan_status(dev, value);
+	if (ret)
+		return ret;
+
+	dev->force_fan = value;
 
 	return count;
 }
@@ -1610,7 +1630,6 @@  static ssize_t fan_store(struct device *dev,
 			 const char *buf, size_t count)
 {
 	struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
-	u32 result;
 	int state;
 	int ret;
 
@@ -1621,11 +1640,9 @@  static ssize_t fan_store(struct device *dev,
 	if (state != 0 && state != 1)
 		return -EINVAL;
 
-	result = hci_write(toshiba, HCI_FAN, state);
-	if (result == TOS_FAILURE)
-		return -EIO;
-	else if (result == TOS_NOT_SUPPORTED)
-		return -ENODEV;
+	ret = set_fan_status(toshiba, state);
+	if (ret)
+		return ret;
 
 	return count;
 }