Skip to contentSkip to conversation

kzalloc conversion in fs/proc

PATCH In review Eric Sesterhenn 6 participants 12 messages Feb 21, 2006 – Feb 22, 2006

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

PATCH 1/1 kzalloc conversion in fs/proc

hi,

this converts fs/proc to kzalloc() usage.

fs/proc/kcore.c renamed from fs/proc/kcore.c.orig +2 -4
@@ -282,12 +282,11 @@ read_kcore(struct file *file, char __use
 		tsz = elf_buflen - *fpos;
 		if (buflen < tsz)
 			tsz = buflen;
-		elf_buf = kmalloc(elf_buflen, GFP_ATOMIC);
+		elf_buf = kzalloc(elf_buflen, GFP_ATOMIC);
 		if (!elf_buf) {
 			read_unlock(&kclist_lock);
 			return -ENOMEM;
 		}
-		memset(elf_buf, 0, elf_buflen);
 		elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen);
 		read_unlock(&kclist_lock);
 		if (copy_to_user(buffer, elf_buf + *fpos, tsz)) {
@@ -333,10 +332,9 @@ read_kcore(struct file *file, char __use
 			unsigned long curstart = start;
 			unsigned long cursize = tsz;
 
-			elf_buf = kmalloc(tsz, GFP_KERNEL);
+			elf_buf = kzalloc(tsz, GFP_KERNEL);
 			if (!elf_buf)
 				return -ENOMEM;
-			memset(elf_buf, 0, tsz);
 
 			read_lock(&vmlist_lock);
 			for (m=vmlist; m && cursize; m=m->next) {
fs/proc/vmcore.c renamed from fs/proc/vmcore.c.orig +1 -6
@@ -179,12 +179,7 @@ struct file_operations proc_vmcore_opera
 
 static struct vmcore* __init get_new_element(void)
 {
-	struct vmcore *p;
-
-	p = kmalloc(sizeof(*p), GFP_KERNEL);
-	if (p)
-		memset(p, 0, sizeof(*p));
-	return p;
+	return = kzalloc(sizeof(struct vmcore), GFP_KERNEL);
 }
 
 static u64 __init get_vmcore_size_elf64(char *elfptr)

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 6 lines · Eric Sesterhenn

hi,

this converts fs/proc to kzalloc() usage.

[snip]

fs/proc/vmcore.c struct file_operations proc_vmcore_opera · line 182

Quoted 10 lines

static struct vmcore* __init get_new_element(void) {

fs/proc/vmcore.c renamed from fs/proc/vmcore.c.orig +1 -6
-       struct vmcore *p;
-
-       p = kmalloc(sizeof(*p), GFP_KERNEL);
-       if (p)
-               memset(p, 0, sizeof(*p));
-       return p;
+       return = kzalloc(sizeof(struct vmcore), GFP_KERNEL);

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

???

--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw
In reply to Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

fs/proc/kcore.c renamed from fs/proc/kcore.c.orig +2 -4
@@ -282,12 +282,11 @@ read_kcore(struct file *file, char __use
 		tsz = elf_buflen - *fpos;
 		if (buflen < tsz)
 			tsz = buflen;
-		elf_buf = kmalloc(elf_buflen, GFP_ATOMIC);
+		elf_buf = kzalloc(elf_buflen, GFP_ATOMIC);
 		if (!elf_buf) {
 			read_unlock(&kclist_lock);
 			return -ENOMEM;
 		}
-		memset(elf_buf, 0, elf_buflen);
 		elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen);
 		read_unlock(&kclist_lock);
 		if (copy_to_user(buffer, elf_buf + *fpos, tsz)) {
@@ -333,10 +332,9 @@ read_kcore(struct file *file, char __use
 			unsigned long curstart = start;
 			unsigned long cursize = tsz;
 
-			elf_buf = kmalloc(tsz, GFP_KERNEL);
+			elf_buf = kzalloc(tsz, GFP_KERNEL);
 			if (!elf_buf)
 				return -ENOMEM;
-			memset(elf_buf, 0, tsz);
 
 			read_lock(&vmlist_lock);
 			for (m=vmlist; m && cursize; m=m->next) {
fs/proc/vmcore.c renamed from fs/proc/vmcore.c.orig +1 -6
@@ -179,12 +179,7 @@ struct file_operations proc_vmcore_opera
 
 static struct vmcore* __init get_new_element(void)
 {
-	struct vmcore *p;
-
-	p = kmalloc(sizeof(*p), GFP_KERNEL);
-	if (p)
-		memset(p, 0, sizeof(*p));
-	return p;
+	return kzalloc(sizeof(struct vmcore), GFP_KERNEL);
 }
 
 static u64 __init get_vmcore_size_elf64(char *elfptr)

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#3 lore raw
In reply to Eric Sesterhenn
Quoted 10 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o

or

$ make fs/proc/

builds it for me. No reason why you couldn't have made the same test.

In any case, noting in the email with the patch what level of testing you've done is usually a good idea.
Just a simple line saying "compile tested" or "compile & run tested" (meaning you've build a kernel with the patch and test booted it), or if you've done even more testing than that, then a line or two specifying exactely what testing you've done, is usually a good idea. And if you've done no testing at all, then a line stating "patch is untested" is really nice.

It helps other people looking over your changes, but it also helps yourself - it's a nice mental "stop-post" when you write the testing info you (at least I know I do) usually look over the patch once more and think about if the testing you've done is sufficient. At least consider it :)

Anyway, the fixed patch looks good to me.

--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#4 lore raw
In reply to Eric Sesterhenn
Quoted 9 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Your config is really easy to change to that it will build, isn't it?
Let's see, PROC_KCORE requires PROC_FS and MMU. Does your kernel build with MMU enabled?
Cause PROC_FS is really easy to change...

Quoted 49 lines
fs/proc/kcore.c renamed from fs/proc/kcore.c.orig +2 -4
@@ -282,12 +282,11 @@ read_kcore(struct file *file, char __use
 		tsz = elf_buflen - *fpos;
 		if (buflen < tsz)
 			tsz = buflen;
-		elf_buf = kmalloc(elf_buflen, GFP_ATOMIC);
+		elf_buf = kzalloc(elf_buflen, GFP_ATOMIC);
 		if (!elf_buf) {
 			read_unlock(&kclist_lock);
 			return -ENOMEM;
 		}
-		memset(elf_buf, 0, elf_buflen);
 		elf_kcore_store_hdr(elf_buf, nphdr, elf_buflen);
 		read_unlock(&kclist_lock);
 		if (copy_to_user(buffer, elf_buf + *fpos, tsz)) {
@@ -333,10 +332,9 @@ read_kcore(struct file *file, char __use
 			unsigned long curstart = start;
 			unsigned long cursize = tsz;
 
-			elf_buf = kmalloc(tsz, GFP_KERNEL);
+			elf_buf = kzalloc(tsz, GFP_KERNEL);
 			if (!elf_buf)
 				return -ENOMEM;
-			memset(elf_buf, 0, tsz);
 
 			read_lock(&vmlist_lock);
 			for (m=vmlist; m && cursize; m=m->next) {
fs/proc/vmcore.c renamed from fs/proc/vmcore.c.orig +1 -6
@@ -179,12 +179,7 @@ struct file_operations proc_vmcore_opera
 
 static struct vmcore* __init get_new_element(void)
 {
-	struct vmcore *p;
-
-	p = kmalloc(sizeof(*p), GFP_KERNEL);
-	if (p)
-		memset(p, 0, sizeof(*p));
-	return p;
+	return kzalloc(sizeof(struct vmcore), GFP_KERNEL);
 }
 
 static u64 __init get_vmcore_size_elf64(char *elfptr)
Signature · 1 line
~Randy

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#5 lore raw
In reply to Eric Sesterhenn
Quoted 8 lines · Jesper Juhl
Quoted 7 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

Quoted 8 lines
Quoted 3 lines

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o

How on earth did this succeed? I always, always get

$ make fs/proc/kcore.o
  SPLIT   include/linux/autoconf.h -> include/config/*
  HOSTCC  scripts/genksyms/genksyms.o
  SHIPPED scripts/genksyms/lex.c
  SHIPPED scripts/genksyms/parse.h
  SHIPPED scripts/genksyms/keywords.c
  HOSTCC  scripts/genksyms/lex.o
  SHIPPED scripts/genksyms/parse.c
  HOSTCC  scripts/genksyms/parse.o
  HOSTLD  scripts/genksyms/genksyms
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/modpost.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTLD  scripts/mod/modpost
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/pnmtologo
  HOSTCC  scripts/conmakehash
  HOSTCC  scripts/bin2c
  CC      fs/proc/kcore.o
In file included from include/linux/mm.h:4,
                 from fs/proc/kcore.c:13:
include/linux/sched.h:4:36: asm/param.h: No such file or directory

Some secret agreement with devil you've signed?

Quoted 5 lines

or

$ make fs/proc/

builds it for me. No reason why you couldn't have made the same test.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#6 lore raw
In reply to Eric Sesterhenn
Quoted 4 lines
Quoted 2 lines
$ make allyesconfig
$ make fs/proc/kcore.o

How on earth did this succeed? I always, always get

works for me too... maybe there were some values
still set and not changed by allyesconfig?
if you want to compare .configs, i placed mine at
http://www.snake-basket.de/misc/config

cu Eric

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#7 lore raw
In reply to Eric Sesterhenn
Quoted 13 lines · Alexey Dobriyan
Quoted 12 lines · Jesper Juhl
Quoted 10 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Quoted 6 lines
Quoted 4 lines

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o

How on earth did this succeed? I always, always get

I'm guessing it might have been a tree he's already built a kernel in before? You usually need to let a normal make go through a few steps before trying this, so that the asm->asm-$arch symlink is created and a few other files are generated, IIRC.

Thanks,
Nish

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#8 lore raw
In reply to Eric Sesterhenn
Quoted 23 lines · Nishanth Aravamudan
Quoted 21 lines · Alexey Dobriyan
Quoted 18 lines · Jesper Juhl
Quoted 11 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o
Quoted 7 lines
Quoted 1 line

How on earth did this succeed? I always, always get

I'm guessing it might have been a tree he's already built a kernel in before? You usually need to let a normal make go through a few steps before trying this, so that the asm->asm-$arch symlink is created and a few other files are generated, IIRC.

That imho constitutes a dependancy bug in the build process. After all, it is rather obvious from the error that include/linux/sched.h depends on asm/param.h, but obviously param.h doesn't exist yet. Presumably this is due to the asm link not being created yet. But surely there is a way to "force" the issue with make?

Jaco

Signature · 3 lines
There are only 10 kinds of people in this world,
  those that understand binary and those that don't.
http://www.kroon.co.za/

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#9 lore raw
In reply to Eric Sesterhenn
Quoted 32 lines · Jaco Kroon
Quoted 23 lines · Nishanth Aravamudan
Quoted 21 lines · Alexey Dobriyan
Quoted 18 lines · Jesper Juhl
Quoted 11 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o
Quoted 7 lines
Quoted 1 line

How on earth did this succeed? I always, always get

I'm guessing it might have been a tree he's already built a kernel in before? You usually need to let a normal make go through a few steps before trying this, so that the asm->asm-$arch symlink is created and a few other files are generated, IIRC.

Quoted 5 lines

That imho constitutes a dependancy bug in the build process. After all, it is rather obvious from the error that include/linux/sched.h depends on asm/param.h, but obviously param.h doesn't exist yet. Presumably this is due to the asm link not being created yet. But surely there is a way to "force" the issue with make?

Could be... I'll wait to hear what Alexey says (an ls -l include in the kernel source dir is sufficient). I would have that the make fs/proc/kcore.o would have done whatever it needed, as well, but maybe not. Like I said, the easiest way is to just let plan "make" do its thing for a few steps.

Thanks,
Nish

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#10 lore raw
In reply to Eric Sesterhenn
Quoted 39 lines · Nishanth Aravamudan
Quoted 32 lines · Jaco Kroon
Quoted 23 lines · Nishanth Aravamudan
Quoted 21 lines · Alexey Dobriyan
Quoted 18 lines · Jesper Juhl
Quoted 11 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o
Quoted 7 lines
Quoted 1 line

How on earth did this succeed? I always, always get

I'm guessing it might have been a tree he's already built a kernel in before? You usually need to let a normal make go through a few steps before trying this, so that the asm->asm-$arch symlink is created and a few other files are generated, IIRC.

Quoted 5 lines

That imho constitutes a dependancy bug in the build process. After all, it is rather obvious from the error that include/linux/sched.h depends on asm/param.h, but obviously param.h doesn't exist yet. Presumably this is due to the asm link not being created yet. But surely there is a way to "force" the issue with make?

Quoted 5 lines

Could be... I'll wait to hear what Alexey says (an ls -l include in the kernel source dir is sufficient). I would have that the make fs/proc/kcore.o would have done whatever it needed, as well, but maybe not. Like I said, the easiest way is to just let plan "make" do its thing for a few steps.

Umm. That's me assuming clean tree from the beggining. Actually I think, if

make allyesconfig
make fs/proc/kcore.o

complains, it's a bug. And, IIRC,

make allyesconfig
make archprepare
make fs/proc/kcore.o

doesn't work on some non-x86 targets, so I've given up on archprepare for my cross-build scripts long ago. I'll make some buzz on l-k.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#11 lore raw
In reply to Eric Sesterhenn
Quoted 13 lines · Alexey Dobriyan
Quoted 12 lines · Jesper Juhl
Quoted 10 lines · Eric Sesterhenn
Quoted 5 lines · Jesper Juhl

This looks broken - did you even compile test that patch?

Don't you mean :

return kzalloc(sizeof(struct vmcore), GFP_KERNEL);

*yuck*, sorry for this, didnt compile test since it doesnt build with my config. fixed patch below.

Quoted 7 lines
Quoted 4 lines

Hmm, a simple

$ make allyesconfig
$ make fs/proc/kcore.o

How on earth did this succeed? I always, always get

[snip build failure]

Quoted 3 lines

Some secret agreement with devil you've signed?

I took a second look at my tree and it turns out I did a previous

$ make allyesconfig
$ make

in there. I'd completely forgotten to clean it first, I just deleted the .o file, so what I actually did turns out to be:

$ make allyesconfig
$ make
$ rm fs/proc/kcore.o
$ make allyesconfig
$ make fs/proc/kcore.o

--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors