linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iSeries: Don't leak if allocations fail in mf_getSrcHistory
@ 2010-10-30 17:20 Jesper Juhl
  2010-11-01 11:10 ` Michael Ellerman
  0 siblings, 1 reply; 11+ messages in thread
From: Jesper Juhl @ 2010-10-30 17:20 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Paul Mackerras, linux-kernel

Hi,

If memory is tight and a dynamic allocation fails there's no reason to 
make a bad situation worse by leaking memory.

mf_getSrcHistory potentially leaks pages[0-3]. I believe the right thing 
to do is to free that memory again before returning -ENOMEM - which is 
what this patch does.

I realize that the function is under '#if 0' so this probably doesn't 
matter much, but I assume that the function is still there for a reason 
(but I could be wrong, I don't know the powerpc code).
Anyway, I suggest we remove the leak.

Please keep me on CC when replying.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 mf.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/iseries/mf.c b/arch/powerpc/platforms/iseries/mf.c
index 42d0a88..f67522a 100644
--- a/arch/powerpc/platforms/iseries/mf.c
+++ b/arch/powerpc/platforms/iseries/mf.c
@@ -1058,8 +1058,13 @@ static void mf_getSrcHistory(char *buffer, int size)
 	pages[2] = kmalloc(4096, GFP_ATOMIC);
 	pages[3] = kmalloc(4096, GFP_ATOMIC);
 	if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
-			 || (pages[2] == NULL) || (pages[3] == NULL))
+			 || (pages[2] == NULL) || (pages[3] == NULL)) {
+		kfree(pages[3]);
+		kfree(pages[2]);
+		kfree(pages[1]);
+		kfree(pages[0]);
 		return -ENOMEM;
+	}
 
 	return_stuff.xType = 0;
 	return_stuff.xRc = 0;


-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html

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

end of thread, other threads:[~2010-11-18 22:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-30 17:20 [PATCH] iSeries: Don't leak if allocations fail in mf_getSrcHistory Jesper Juhl
2010-11-01 11:10 ` Michael Ellerman
2010-11-01 20:10   ` Stephen Rothwell
2010-11-01 20:06     ` [PATCH] iSeries: Remove unused mf_getSrcHistory function Jesper Juhl
2010-11-01 21:26       ` Stephen Rothwell
2010-11-01 21:20         ` Jesper Juhl
2010-11-02  0:20           ` Michael Ellerman
2010-11-04 23:29             ` [PATCH v2] iSeries: Remove unused mf_getSrcHistory function and caller Jesper Juhl
2010-11-18 19:45               ` Jesper Juhl
2010-11-18 21:57                 ` Michael Ellerman
2010-11-18 21:51                   ` Jesper Juhl

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