2020-10-29 07:38:45

by Zou Wei

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

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 <[email protected]>
Signed-off-by: Zou Wei <[email protected]>
---
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