firmware: tegra: Switch over to memdup_user()
authorQing Wang <wangqing@vivo.com>
Mon, 18 Oct 2021 11:31:52 +0000 (04:31 -0700)
committerThierry Reding <treding@nvidia.com>
Thu, 15 Sep 2022 10:45:42 +0000 (12:45 +0200)
This patch fixes the following Coccinelle warning:

drivers/firmware/tegra/bpmp-debugfs.c:379: WARNING opportunity for memdup_user

Use memdup_user() rather than duplicating its implementation. This is a
little bit restricted to reduce false positives.

Signed-off-by: Qing Wang <wangqing@vivo.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/firmware/tegra/bpmp-debugfs.c

index 0c440afd522479bc62a0c81d284bdc4986806ece..9d3874cdaaeefc567e1be8b31d3915a74ad709c9 100644 (file)
@@ -377,18 +377,11 @@ static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
        if (!filename)
                return -ENOENT;
 
-       databuf = kmalloc(count, GFP_KERNEL);
-       if (!databuf)
-               return -ENOMEM;
-
-       if (copy_from_user(databuf, buf, count)) {
-               err = -EFAULT;
-               goto free_ret;
-       }
+       databuf = memdup_user(buf, count);
+       if (IS_ERR(databuf))
+               return PTR_ERR(databuf);
 
        err = mrq_debug_write(bpmp, filename, databuf, count);
-
-free_ret:
        kfree(databuf);
 
        return err ?: count;