Skip to content

Commit 5cdc45e

Browse files
committed
platform/x86: hp-wmi: Convert simple_strtoul() to kstrtou32()
First of all, unsigned long can overflow u32 value on 64-bit machine. Second, simple_strtoul() doesn't check for overflow in the input. Convert simple_strtoul() to kstrtou32() to eliminate above issues. Signed-off-by: Andy Shevchenko <[email protected]>
1 parent 7640cd0 commit 5cdc45e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/platform/x86/hp-wmi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,14 @@ static ssize_t postcode_show(struct device *dev, struct device_attribute *attr,
461461
static ssize_t als_store(struct device *dev, struct device_attribute *attr,
462462
const char *buf, size_t count)
463463
{
464-
u32 tmp = simple_strtoul(buf, NULL, 10);
465-
int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_WRITE, &tmp,
464+
u32 tmp;
465+
int ret;
466+
467+
ret = kstrtou32(buf, 10, &tmp);
468+
if (ret)
469+
return ret;
470+
471+
ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_WRITE, &tmp,
466472
sizeof(tmp), sizeof(tmp));
467473
if (ret)
468474
return ret < 0 ? ret : -EINVAL;

0 commit comments

Comments
 (0)