Skip to content

Commit 860a2e7

Browse files
Alexey Dobriyanakpm00
authored andcommitted
proc: use initializer for clearing some buffers
Save LOC by using dark magic of initialisation instead of memset(). Those buffer aren't passed to userspace directly so padding is not an issue. Link: https://lkml.kernel.org/r/3821d3a2-6e10-4629-b0d5-9519d828ab72@p183 Signed-off-by: Alexey Dobriyan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 867046c commit 860a2e7

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

fs/proc/base.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,10 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
11531153
static ssize_t oom_adj_write(struct file *file, const char __user *buf,
11541154
size_t count, loff_t *ppos)
11551155
{
1156-
char buffer[PROC_NUMBUF];
1156+
char buffer[PROC_NUMBUF] = {};
11571157
int oom_adj;
11581158
int err;
11591159

1160-
memset(buffer, 0, sizeof(buffer));
11611160
if (count > sizeof(buffer) - 1)
11621161
count = sizeof(buffer) - 1;
11631162
if (copy_from_user(buffer, buf, count)) {
@@ -1213,11 +1212,10 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
12131212
static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
12141213
size_t count, loff_t *ppos)
12151214
{
1216-
char buffer[PROC_NUMBUF];
1215+
char buffer[PROC_NUMBUF] = {};
12171216
int oom_score_adj;
12181217
int err;
12191218

1220-
memset(buffer, 0, sizeof(buffer));
12211219
if (count > sizeof(buffer) - 1)
12221220
count = sizeof(buffer) - 1;
12231221
if (copy_from_user(buffer, buf, count)) {
@@ -1358,13 +1356,13 @@ static ssize_t proc_fault_inject_write(struct file * file,
13581356
const char __user * buf, size_t count, loff_t *ppos)
13591357
{
13601358
struct task_struct *task;
1361-
char buffer[PROC_NUMBUF];
1359+
char buffer[PROC_NUMBUF] = {};
13621360
int make_it_fail;
13631361
int rv;
13641362

13651363
if (!capable(CAP_SYS_RESOURCE))
13661364
return -EPERM;
1367-
memset(buffer, 0, sizeof(buffer));
1365+
13681366
if (count > sizeof(buffer) - 1)
13691367
count = sizeof(buffer) - 1;
13701368
if (copy_from_user(buffer, buf, count))
@@ -1509,11 +1507,10 @@ sched_autogroup_write(struct file *file, const char __user *buf,
15091507
{
15101508
struct inode *inode = file_inode(file);
15111509
struct task_struct *p;
1512-
char buffer[PROC_NUMBUF];
1510+
char buffer[PROC_NUMBUF] = {};
15131511
int nice;
15141512
int err;
15151513

1516-
memset(buffer, 0, sizeof(buffer));
15171514
if (count > sizeof(buffer) - 1)
15181515
count = sizeof(buffer) - 1;
15191516
if (copy_from_user(buffer, buf, count))
@@ -1666,10 +1663,9 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
16661663
{
16671664
struct inode *inode = file_inode(file);
16681665
struct task_struct *p;
1669-
char buffer[TASK_COMM_LEN];
1666+
char buffer[TASK_COMM_LEN] = {};
16701667
const size_t maxlen = sizeof(buffer) - 1;
16711668

1672-
memset(buffer, 0, sizeof(buffer));
16731669
if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count))
16741670
return -EFAULT;
16751671

fs/proc/task_mmu.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,7 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss,
849849
static int show_smap(struct seq_file *m, void *v)
850850
{
851851
struct vm_area_struct *vma = v;
852-
struct mem_size_stats mss;
853-
854-
memset(&mss, 0, sizeof(mss));
852+
struct mem_size_stats mss = {};
855853

856854
smap_gather_stats(vma, &mss, 0);
857855

@@ -877,7 +875,7 @@ static int show_smap(struct seq_file *m, void *v)
877875
static int show_smaps_rollup(struct seq_file *m, void *v)
878876
{
879877
struct proc_maps_private *priv = m->private;
880-
struct mem_size_stats mss;
878+
struct mem_size_stats mss = {};
881879
struct mm_struct *mm = priv->mm;
882880
struct vm_area_struct *vma;
883881
unsigned long vma_start = 0, last_vma_end = 0;
@@ -893,8 +891,6 @@ static int show_smaps_rollup(struct seq_file *m, void *v)
893891
goto out_put_task;
894892
}
895893

896-
memset(&mss, 0, sizeof(mss));
897-
898894
ret = mmap_read_lock_killable(mm);
899895
if (ret)
900896
goto out_put_mm;
@@ -1246,14 +1242,13 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
12461242
size_t count, loff_t *ppos)
12471243
{
12481244
struct task_struct *task;
1249-
char buffer[PROC_NUMBUF];
1245+
char buffer[PROC_NUMBUF] = {};
12501246
struct mm_struct *mm;
12511247
struct vm_area_struct *vma;
12521248
enum clear_refs_types type;
12531249
int itype;
12541250
int rv;
12551251

1256-
memset(buffer, 0, sizeof(buffer));
12571252
if (count > sizeof(buffer) - 1)
12581253
count = sizeof(buffer) - 1;
12591254
if (copy_from_user(buffer, buf, count))

0 commit comments

Comments
 (0)