Merge tag 'drm-next-2021-09-10' of git://anongit.freedesktop.org/drm/drm
[linux-2.6-microblaze.git] / drivers / acpi / custom_method.c
index 443fdf6..d39a9b4 100644 (file)
@@ -42,6 +42,8 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
                                   sizeof(struct acpi_table_header)))
                        return -EFAULT;
                uncopied_bytes = max_size = table.length;
+               /* make sure the buf is not allocated */
+               kfree(buf);
                buf = kzalloc(max_size, GFP_KERNEL);
                if (!buf)
                        return -ENOMEM;
@@ -55,6 +57,7 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
            (*ppos + count < count) ||
            (count > uncopied_bytes)) {
                kfree(buf);
+               buf = NULL;
                return -EINVAL;
        }
 
@@ -76,7 +79,6 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
                add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
        }
 
-       kfree(buf);
        return count;
 }