lkml.org 
[lkml]   [2022]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5] mm/ksm: introduce ksm_force for each process
On 5/8/22 4:27 PM, cgel.zte@gmail.com wrote:
> +static ssize_t ksm_force_write(struct file *file, const char __user *buf,
> + size_t count, loff_t *ppos)
> +{
> + struct task_struct *task;
> + struct mm_struct *mm;
> + char buffer[PROC_NUMBUF];
> + int force;
> + int err = 0;
> +
> + memset(buffer, 0, sizeof(buffer));
> + if (count > sizeof(buffer) - 1)
> + count = sizeof(buffer) - 1;
> + if (copy_from_user(buffer, buf, count)) {
> + err = -EFAULT;
> + goto out_return;
> + }

This one looks like over-zeroing to me. You don't need to zero
all elements in the array. You're going to overwrite it with
`copy_from_user()` anyway.

Just zero the last potentially useful element by using @count
as the index. It can be like this:

```
char buffer[PROC_NUMBUF];

if (count > sizeof(buffer) - 1)
count = sizeof(buffer) - 1;
if (copy_from_user(buffer, buf, count))
return -EFAULT;
buffer[count] = '\0';
```

--
Ammar Faizi

\
 
 \ /
  Last update: 2022-05-10 22:12    [W:0.358 / U:0.276 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site