[PATCH -next] firmware: tegra: Use memdup_user() as a cleanup

From: Zou Wei
Date: Wed Oct 28 2020 - 18:25:49 EST


Fix coccicheck warning which recommends to use memdup_user().

This patch fixes the following coccicheck warning:

./drivers/firmware/tegra/bpmp-debugfs.c:335:11-18: WARNING opportunity for memdup_user

Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug")
Reported-by: Hulk Robot <hulkci@xxxxxxxxxx>
Signed-off-by: Zou Wei <zou_wei@xxxxxxxxxx>
---
drivers/firmware/tegra/bpmp-debugfs.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
index c1bbba9..7234136 100644
--- a/drivers/firmware/tegra/bpmp-debugfs.c
+++ b/drivers/firmware/tegra/bpmp-debugfs.c
@@ -332,12 +332,9 @@ 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;
+ databuf = memdup_user(buf, count);
+ if (IS_ERR(databuf)) {
+ err = PTR_ERR(databuf);
goto free_ret;
}

--
2.6.2