platform/x86: intel_pmc_core: Respect error code of kstrtou32_from_user()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Wed, 18 Dec 2019 18:42:29 +0000 (20:42 +0200)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 10 Jan 2020 09:50:32 +0000 (11:50 +0200)
kstrtou32_from_user() may return different error codes on certain
circumstances. Respect all possible values.

While here, move it out of the lock: there is no data access that lock guards.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/platform/x86/intel_pmc_core.c

index 92d4b47..4a20540 100644 (file)
@@ -629,15 +629,15 @@ static ssize_t pmc_core_ltr_ignore_write(struct file *file, const char __user
        struct pmc_dev *pmcdev = &pmc;
        const struct pmc_reg_map *map = pmcdev->map;
        u32 val, buf_size, fd;
-       int err = 0;
+       int err;
 
        buf_size = count < 64 ? count : 64;
-       mutex_lock(&pmcdev->lock);
 
-       if (kstrtou32_from_user(userbuf, buf_size, 10, &val)) {
-               err = -EFAULT;
-               goto out_unlock;
-       }
+       err = kstrtou32_from_user(userbuf, buf_size, 10, &val);
+       if (err)
+               return err;
+
+       mutex_lock(&pmcdev->lock);
 
        if (val > map->ltr_ignore_max) {
                err = -EINVAL;