Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Azael Avalos <coproscefalo@gmail.com>
Signed-off-by: Darren Hart <dvhart@linux.intel.com>

authored by

Azael Avalos and committed by
Darren Hart
a8820037 63ba3e28

+18 -8
+18 -8
drivers/platform/x86/toshiba_haps.c
··· 78 78 const char *buf, size_t count) 79 79 { 80 80 struct toshiba_haps_dev *haps = dev_get_drvdata(dev); 81 - int level, ret; 81 + int level; 82 + int ret; 82 83 83 - if (sscanf(buf, "%d", &level) != 1 || level < 0 || level > 3) 84 - return -EINVAL; 85 - 86 - /* Set the sensor level. 87 - * Acceptable levels are: 84 + ret = kstrtoint(buf, 0, &level); 85 + if (ret) 86 + return ret; 87 + /* 88 + * Check for supported levels, which can be: 88 89 * 0 - Disabled | 1 - Low | 2 - Medium | 3 - High 89 90 */ 91 + if (level < 0 || level > 3) 92 + return -EINVAL; 93 + 94 + /* Set the sensor level */ 90 95 ret = toshiba_haps_protection_level(haps->acpi_dev->handle, level); 91 96 if (ret != 0) 92 97 return ret; ··· 106 101 const char *buf, size_t count) 107 102 { 108 103 struct toshiba_haps_dev *haps = dev_get_drvdata(dev); 109 - int reset, ret; 104 + int reset; 105 + int ret; 110 106 111 - if (sscanf(buf, "%d", &reset) != 1 || reset != 1) 107 + ret = kstrtoint(buf, 0, &reset); 108 + if (ret) 109 + return ret; 110 + /* The only accepted value is 1 */ 111 + if (reset != 1) 112 112 return -EINVAL; 113 113 114 114 /* Reset the protection interface */