LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c
@ 2008-02-15 11:13 Thomas Petazzoni
  2008-02-15 14:46 ` Jan Engelhardt
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Petazzoni @ 2008-02-15 11:13 UTC (permalink / raw)
  To: linux-kernel, Andrew Morton, mpm

[-- Attachment #1: Type: text/plain, Size: 1988 bytes --]

Instead of using the malloc() and free() wrappers needed by the
lib/inflate.c code for allocations, simply use kmalloc() and kfree() in
the initramfs code. This is needed for a further lib/inflate.c-related
cleanup patch that will remove the malloc() and free() functions.

Based of work done by Matt Mackall <mpm@selenic.com>.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

---
 init/initramfs.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Index: linux/init/initramfs.c
===================================================================
--- linux.orig/init/initramfs.c
+++ linux/init/initramfs.c
@@ -57,7 +57,7 @@
 			continue;
 		return (*p)->name;
 	}
-	q = (struct hash *)malloc(sizeof(struct hash));
+	q = (struct hash *)kmalloc(sizeof(struct hash), GFP_KERNEL);
 	if (!q)
 		panic("can't allocate link hash entry");
 	q->major = major;
@@ -77,7 +77,7 @@
 		while (*p) {
 			q = *p;
 			*p = q->next;
-			free(q);
+			kfree(q);
 		}
 	}
 }
@@ -445,10 +445,10 @@
 {
 	int written;
 	dry_run = check_only;
-	header_buf = malloc(110);
-	symlink_buf = malloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1);
-	name_buf = malloc(N_ALIGN(PATH_MAX));
-	window = malloc(WSIZE);
+	header_buf = kmalloc(110, GFP_KERNEL);
+	symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
+	name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
+	window = kmalloc(WSIZE, GFP_KERNEL);
 	if (!window || !header_buf || !symlink_buf || !name_buf)
 		panic("can't allocate buffers");
 	state = Start;
@@ -484,10 +484,10 @@
 		buf += inptr;
 		len -= inptr;
 	}
-	free(window);
-	free(name_buf);
-	free(symlink_buf);
-	free(header_buf);
+	kfree(window);
+	kfree(name_buf);
+	kfree(symlink_buf);
+	kfree(header_buf);
 	return message;
 }
 


-- 
Thomas Petazzoni, Free Electrons
Free Embedded Linux Training Materials
on http://free-electrons.com/training
(More than 1500 pages!)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c
  2008-02-15 11:13 [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c Thomas Petazzoni
@ 2008-02-15 14:46 ` Jan Engelhardt
  2008-02-15 15:45   ` Thomas Petazzoni
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2008-02-15 14:46 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: Linux Kernel Mailing List, Andrew Morton, mpm


On Feb 15 2008 12:13, Thomas Petazzoni wrote:
>+++ linux/init/initramfs.c
>@@ -57,7 +57,7 @@
> 			continue;
> 		return (*p)->name;
> 	}
>-	q = (struct hash *)malloc(sizeof(struct hash));
>+	q = (struct hash *)kmalloc(sizeof(struct hash), GFP_KERNEL);

Remove the cast while you are at it, thanks :)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c
  2008-02-15 14:46 ` Jan Engelhardt
@ 2008-02-15 15:45   ` Thomas Petazzoni
  2008-02-15 16:00     ` Jan Engelhardt
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Petazzoni @ 2008-02-15 15:45 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Linux Kernel Mailing List, Andrew Morton, mpm

[-- Attachment #1: Type: text/plain, Size: 2441 bytes --]

Hi,

Le Fri, 15 Feb 2008 15:46:47 +0100 (CET),
Jan Engelhardt <jengelh@computergmbh.de> a écrit :

> Remove the cast while you are at it, thanks :)

Right, thanks for the comment. Here is an updated patch. Who will pick
it up ? There doesn't seem to be a maintainer for the initramfs code
(not in MAINTAINERS, not in the init/initramfs.c file itself).

Thanks,

Thomas

---

Instead of using the malloc() and free() wrappers needed by the
lib/inflate.c code for allocations, simply use kmalloc() and kfree() in
the initramfs code. This is needed for a further lib/inflate.c-related
cleanup patch that will remove the malloc() and free() functions.

Take that opportunity to remove the useless kmalloc() return value
cast.

Based of work done by Matt Mackall <mpm@selenic.com>.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 init/initramfs.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Index: linux/init/initramfs.c
===================================================================
--- linux.orig/init/initramfs.c
+++ linux/init/initramfs.c
@@ -57,7 +57,7 @@
 			continue;
 		return (*p)->name;
 	}
-	q = (struct hash *)malloc(sizeof(struct hash));
+	q = kmalloc(sizeof(struct hash), GFP_KERNEL);
 	if (!q)
 		panic("can't allocate link hash entry");
 	q->major = major;
@@ -77,7 +77,7 @@
 		while (*p) {
 			q = *p;
 			*p = q->next;
-			free(q);
+			kfree(q);
 		}
 	}
 }
@@ -445,10 +445,10 @@
 {
 	int written;
 	dry_run = check_only;
-	header_buf = malloc(110);
-	symlink_buf = malloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1);
-	name_buf = malloc(N_ALIGN(PATH_MAX));
-	window = malloc(WSIZE);
+	header_buf = kmalloc(110, GFP_KERNEL);
+	symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
+	name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
+	window = kmalloc(WSIZE, GFP_KERNEL);
 	if (!window || !header_buf || !symlink_buf || !name_buf)
 		panic("can't allocate buffers");
 	state = Start;
@@ -484,10 +484,10 @@
 		buf += inptr;
 		len -= inptr;
 	}
-	free(window);
-	free(name_buf);
-	free(symlink_buf);
-	free(header_buf);
+	kfree(window);
+	kfree(name_buf);
+	kfree(symlink_buf);
+	kfree(header_buf);
 	return message;
 }
 


-- 
Thomas Petazzoni, Free Electrons
Free Embedded Linux Training Materials
on http://free-electrons.com/training
(More than 1500 pages!)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c
  2008-02-15 15:45   ` Thomas Petazzoni
@ 2008-02-15 16:00     ` Jan Engelhardt
  2008-02-15 16:04       ` Thomas Petazzoni
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Engelhardt @ 2008-02-15 16:00 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: Linux Kernel Mailing List, Andrew Morton, mpm


On Feb 15 2008 16:45, Thomas Petazzoni wrote:
>
>> Remove the cast while you are at it, thanks :)
>
>Right, thanks for the comment. Here is an updated patch. Who will pick
>it up ? There doesn't seem to be a maintainer for the initramfs code
>(not in MAINTAINERS, not in the init/initramfs.c file itself).

Anyone you can get to push the actual changeset; many won't feel
responsible :) so the path is through ->akpm->linus here.

BTW, if you changed free to kfree, did the free macro/whatever get 
removed or is it still used?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c
  2008-02-15 16:00     ` Jan Engelhardt
@ 2008-02-15 16:04       ` Thomas Petazzoni
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni @ 2008-02-15 16:04 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Linux Kernel Mailing List, Andrew Morton, mpm

[-- Attachment #1: Type: text/plain, Size: 842 bytes --]

Le Fri, 15 Feb 2008 17:00:35 +0100 (CET),
Jan Engelhardt <jengelh@computergmbh.de> a écrit :

> Anyone you can get to push the actual changeset; many won't feel
> responsible :) so the path is through ->akpm->linus here.

Ok, so as Andrew is in Cc:, I suppose he will pick the patch :-)

> BTW, if you changed free to kfree, did the free macro/whatever get 
> removed or is it still used?

After this patch, they are still used by the lib/inflate.c code. But if
you look at the patch called "inflate: refactor inflate malloc code"
that I sent to the LKML this morning, you'll see that it removes the
malloc() and free() wrappers (and does some more clean-up).

Sincerly,

Thomas
-- 
Thomas Petazzoni, Free Electrons
Free Embedded Linux Training Materials
on http://free-electrons.com/training
(More than 1500 pages!)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-02-15 16:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-15 11:13 [PATCH] Use directly kmalloc() and kfree() in init/initramfs.c Thomas Petazzoni
2008-02-15 14:46 ` Jan Engelhardt
2008-02-15 15:45   ` Thomas Petazzoni
2008-02-15 16:00     ` Jan Engelhardt
2008-02-15 16:04       ` Thomas Petazzoni

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).