Skip to contentSkip to conversation

kgdb: Removed kmalloc returned value cast

PATCH In review Alex Grad 3 participants 3 messages Mar 10, 2013 PowerPC

lore
Share & tools
lore

Alex Grad

author
#0 lore raw

PATCH 1/1 kgdb: Removed kmalloc returned value cast

---
 arch/powerpc/kernel/kgdb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/kgdb.c +1 -1
index 5ca82cd..c1eef24 100644
@@ -159,7 +159,7 @@ static int kgdb_singlestep(struct pt_regs *regs)
 	if (user_mode(regs))
 		return 0;
 
-	backup_current_thread_info = (struct thread_info *)kmalloc(sizeof(struct thread_info), GFP_KERNEL);
+	backup_current_thread_info = kmalloc(sizeof(struct thread_info), GFP_KERNEL);
 	/*
 	 * On Book E and perhaps other processors, singlestep is handled on
 	 * the critical exception stack.  This causes current_thread_info()
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 10 lines · Alex Grad
---
 arch/powerpc/kernel/kgdb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/kgdb.c +0 -0
index 5ca82cd..c1eef24 100644

arch/powerpc/kernel/kgdb.c static int kgdb_singlestep(struct pt_regs *regs) · line 162

Quoted 5 lines
arch/powerpc/kernel/kgdb.c +1 -1
@@ -159,7 +159,7 @@ static int kgdb_singlestep(struct pt_regs *regs)
        if (user_mode(regs))
                return 0;
 
-       backup_current_thread_info = (struct thread_info *)kmalloc(sizeof(struct thread_info), GFP_KERNEL);
+       backup_current_thread_info = kmalloc(sizeof(struct thread_info), GFP_KERNEL);

Looks good to me.

There's two additional problems in the kgdb_singlestep() function: it doesn't check if the kmalloc() call fails nor does it kfree() the allocated memory.

Pekka

#2 lore raw
Quoted 14 lines · Pekka Enberg
Quoted 13 lines · Alex Grad
---
 arch/powerpc/kernel/kgdb.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/kgdb.c +0 -0
index 5ca82cd..c1eef24 100644
@@ -159,7 +159,7 @@ static int kgdb_singlestep(struct pt_regs *regs)
        if (user_mode(regs))
                return 0;
 
Quoted 8 lines

arch/powerpc/kernel/kgdb.c static int kgdb_singlestep(struct pt_regs *regs) · line 162

Quoted 2 lines
arch/powerpc/kernel/kgdb.c +1 -1
-       backup_current_thread_info = (struct thread_info *)kmalloc(sizeof(struct thread_info), GFP_KERNEL);
+       backup_current_thread_info = kmalloc(sizeof(struct thread_info), GFP_KERNEL);

Looks good to me.

There's two additional problems in the kgdb_singlestep() function: it doesn't check if the kmalloc() call fails nor does it kfree() the allocated memory.

Hi Pekka,

Indeed there is no check if kmalloc() fails. This should be fixed.

Anyhow, commit fefd9e6f powerpc: kernel/kgdb.c: Fix memory leakage fixed the problem with kfree.

thanks,
Daniel.