* [PATCH] firmware: tegra: switch over to memdup_user()
@ 2021-10-18 7:59 Qing Wang
2021-10-21 1:15 ` Michał Mirosław
[not found] ` <AJsAPABcEiDeZ4ZDMvu*CapV.9.1634778945247.Hmail.wangqing@vivo.com>
0 siblings, 2 replies; 4+ messages in thread
From: Qing Wang @ 2021-10-18 7:59 UTC (permalink / raw)
To: Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel; +Cc: Qing Wang
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>
---
drivers/firmware/tegra/bpmp-debugfs.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
index 6d66fe0..0435709
--- a/drivers/firmware/tegra/bpmp-debugfs.c
+++ b/drivers/firmware/tegra/bpmp-debugfs.c
@@ -376,18 +376,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 ERR_PTR(PTR_ERR(databuf));
err = mrq_debug_write(bpmp, filename, databuf, count);
-
-free_ret:
kfree(databuf);
return err ?: count;
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] firmware: tegra: switch over to memdup_user()
2021-10-18 7:59 [PATCH] firmware: tegra: switch over to memdup_user() Qing Wang
@ 2021-10-21 1:15 ` Michał Mirosław
[not found] ` <AJsAPABcEiDeZ4ZDMvu*CapV.9.1634778945247.Hmail.wangqing@vivo.com>
1 sibling, 0 replies; 4+ messages in thread
From: Michał Mirosław @ 2021-10-21 1:15 UTC (permalink / raw)
To: Qing Wang; +Cc: Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel
On Mon, Oct 18, 2021 at 12:59:40AM -0700, Qing Wang wrote:
[...]
> --- a/drivers/firmware/tegra/bpmp-debugfs.c
> +++ b/drivers/firmware/tegra/bpmp-debugfs.c
> @@ -376,18 +376,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 ERR_PTR(PTR_ERR(databuf));
ERR_PTR() is too much here.
Best Regards
Michał Mirosław
^ permalink raw reply [flat|nested] 4+ messages in thread
* 回复: [PATCH] firmware: tegra: switch over to memdup_user()
[not found] ` <AJsAPABcEiDeZ4ZDMvu*CapV.9.1634778945247.Hmail.wangqing@vivo.com>
@ 2021-10-21 1:27 ` 王擎
0 siblings, 0 replies; 4+ messages in thread
From: 王擎 @ 2021-10-21 1:27 UTC (permalink / raw)
To: Michał Mirosław
Cc: Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel
>> --- a/drivers/firmware/tegra/bpmp-debugfs.c
>> +++ b/drivers/firmware/tegra/bpmp-debugfs.c
>> @@ -376,18 +376,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 ERR_PTR(PTR_ERR(databuf));
>
>ERR_PTR() is too much here.
>
>Best Regards
>Michał Mirosław
Sorry about that, I have resent the patch, Please ignore this version.
Thanks,
Qing
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] firmware: tegra: switch over to memdup_user()
@ 2021-10-18 11:31 Qing Wang
0 siblings, 0 replies; 4+ messages in thread
From: Qing Wang @ 2021-10-18 11:31 UTC (permalink / raw)
To: Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel; +Cc: Qing Wang
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>
---
drivers/firmware/tegra/bpmp-debugfs.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
index 6d66fe0..0435709
--- a/drivers/firmware/tegra/bpmp-debugfs.c
+++ b/drivers/firmware/tegra/bpmp-debugfs.c
@@ -376,18 +376,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;
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-21 1:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 7:59 [PATCH] firmware: tegra: switch over to memdup_user() Qing Wang
2021-10-21 1:15 ` Michał Mirosław
[not found] ` <AJsAPABcEiDeZ4ZDMvu*CapV.9.1634778945247.Hmail.wangqing@vivo.com>
2021-10-21 1:27 ` 回复: " 王擎
2021-10-18 11:31 Qing Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).