Commit a8820037 authored by Azael Avalos's avatar Azael Avalos Committed by Darren Hart

toshiba_haps: Replace sscanf with kstrtoint

This patch simply replaces the use of sscanf with kstrtoint returning
the error code in case that something went bad.
Signed-off-by: default avatarAzael Avalos <coproscefalo@gmail.com>
Signed-off-by: default avatarDarren Hart <dvhart@linux.intel.com>
parent 63ba3e28
...@@ -78,15 +78,20 @@ static ssize_t protection_level_store(struct device *dev, ...@@ -78,15 +78,20 @@ static ssize_t protection_level_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct toshiba_haps_dev *haps = dev_get_drvdata(dev); struct toshiba_haps_dev *haps = dev_get_drvdata(dev);
int level, ret; int level;
int ret;
if (sscanf(buf, "%d", &level) != 1 || level < 0 || level > 3)
return -EINVAL;
/* Set the sensor level. ret = kstrtoint(buf, 0, &level);
* Acceptable levels are: if (ret)
return ret;
/*
* Check for supported levels, which can be:
* 0 - Disabled | 1 - Low | 2 - Medium | 3 - High * 0 - Disabled | 1 - Low | 2 - Medium | 3 - High
*/ */
if (level < 0 || level > 3)
return -EINVAL;
/* Set the sensor level */
ret = toshiba_haps_protection_level(haps->acpi_dev->handle, level); ret = toshiba_haps_protection_level(haps->acpi_dev->handle, level);
if (ret != 0) if (ret != 0)
return ret; return ret;
...@@ -101,9 +106,14 @@ static ssize_t reset_protection_store(struct device *dev, ...@@ -101,9 +106,14 @@ static ssize_t reset_protection_store(struct device *dev,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct toshiba_haps_dev *haps = dev_get_drvdata(dev); struct toshiba_haps_dev *haps = dev_get_drvdata(dev);
int reset, ret; int reset;
int ret;
if (sscanf(buf, "%d", &reset) != 1 || reset != 1) ret = kstrtoint(buf, 0, &reset);
if (ret)
return ret;
/* The only accepted value is 1 */
if (reset != 1)
return -EINVAL; return -EINVAL;
/* Reset the protection interface */ /* Reset the protection interface */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment