Skip to contentSkip to conversation

fs: Convert kmalloc()+memset() combo to kzalloc().

PATCH NAK Robert P. J. Day 3 participants 4 messages Dec 3, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: Convert kmalloc()+memset() combo to kzalloc().

Convert all obvious combinations of kmalloc()+memset() to single
kzalloc() in the fs/ directory.

---

 binfmt_elf_fdpic.c |    3 +--
 seq_file.c         |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
fs/binfmt_elf_fdpic.c +1 -2
index f86d5c9..789c1c6 100644
@@ -709,12 +709,11 @@ #endif
 		return -ELIBBAD;
 
 	size = sizeof(*loadmap) + nloads * sizeof(*seg);
-	loadmap = kmalloc(size, GFP_KERNEL);
+	loadmap = kzalloc(size, GFP_KERNEL);
 	if (!loadmap)
 		return -ENOMEM;
 
 	params->loadmap = loadmap;
-	memset(loadmap, 0, size);
 
 	loadmap->version = ELF32_FDPIC_LOADMAP_VERSION;
 	loadmap->nsegs = nloads;
fs/seq_file.c +1 -2
index 555b9ac..f85feba 100644
@@ -31,12 +31,11 @@ int seq_open(struct file *file, struct s
 	struct seq_file *p = file->private_data;
 
 	if (!p) {
-		p = kmalloc(sizeof(*p), GFP_KERNEL);
+		p = kzalloc(sizeof(*p), GFP_KERNEL);
 		if (!p)
 			return -ENOMEM;
 		file->private_data = p;
 	}
-	memset(p, 0, sizeof(*p));
 	mutex_init(&p->lock);
 	p->op = op;
 
NAK
#1 lore raw

fs/seq_file.c int seq_open(struct file *file, struct s · line 40

Quoted 10 lines
fs/seq_file.c +1 -2
 	if (!p) {
-		p = kmalloc(sizeof(*p), GFP_KERNEL);
+		p = kzalloc(sizeof(*p), GFP_KERNEL);
 		if (!p)
 			return -ENOMEM;
 		file->private_data = p;
 	}
-	memset(p, 0, sizeof(*p));
 	mutex_init(&p->lock);
 	p->op = op;

NAK

If p was already set (ie private data existed) the old code zeroed it, your code does not, but only zeroes the new stuff.

Alan

#2 lore raw
Quoted 14 lines · Alan

fs/seq_file.c int seq_open(struct file *file, struct s · line 40

Quoted 10 lines
fs/seq_file.c +1 -2
 	if (!p) {
-		p = kmalloc(sizeof(*p), GFP_KERNEL);
+		p = kzalloc(sizeof(*p), GFP_KERNEL);
 		if (!p)
 			return -ENOMEM;
 		file->private_data = p;
 	}
-	memset(p, 0, sizeof(*p));
 	mutex_init(&p->lock);
 	p->op = op;

NAK

Quoted 2 lines

If p was already set (ie private data existed) the old code zeroed it, your code does not, but only zeroes the new stuff.

whoops, sorry, my bad.

rday

#3 lore raw
In reply to Robert P. J. Day
Quoted 2 lines · Robert P. J. Day

Convert all obvious combinations of kmalloc()+memset() to single
kzalloc() in the fs/ directory.

[snip]

Quoted 7 lines
fs/seq_file.c +0 -0
index 555b9ac..f85feba 100644
@@ -31,12 +31,11 @@ int seq_open(struct file *file, struct s
 	struct seq_file *p = file->private_data;
 

fs/seq_file.c int seq_open(struct file *file, struct s · line 40

Quoted 10 lines
fs/seq_file.c +1 -2
 	if (!p) {
-		p = kmalloc(sizeof(*p), GFP_KERNEL);
+		p = kzalloc(sizeof(*p), GFP_KERNEL);
 		if (!p)
 			return -ENOMEM;
 		file->private_data = p;
 	}
-	memset(p, 0, sizeof(*p));
 	mutex_init(&p->lock);
 	p->op = op;

It's not the same! Previous erases it every time seq_open is called and after your change only once -- when p == NULL.

regards,

Signature · 4 lines
http://www.fi.muni.cz/~xslaby/            Jiri Slaby
faculty of informatics, masaryk university, brno, cz
e-mail: jirislaby gmail com, gpg pubkey fingerprint:
B674 9967 0407 CE62 ACC8  22A0 32CC 55C3 39D4 7A7E