2013-03-10 13:06:40

by Alex Grad

[permalink] [raw]
Subject: [PATCH] kgdb: Removed kmalloc returned value cast

Signed-off-by: Alex Grad <[email protected]>
---
arch/powerpc/kernel/kgdb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
index 5ca82cd..c1eef24 100644
--- a/arch/powerpc/kernel/kgdb.c
+++ b/arch/powerpc/kernel/kgdb.c
@@ -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()
--
1.7.10.4


2013-03-10 14:10:59

by Pekka Enberg

[permalink] [raw]
Subject: Re: [PATCH] kgdb: Removed kmalloc returned value cast

On Sun, Mar 10, 2013 at 3:06 PM, Alex Grad <[email protected]> wrote:
> Signed-off-by: Alex Grad <[email protected]>
> ---
> arch/powerpc/kernel/kgdb.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
> index 5ca82cd..c1eef24 100644
> --- a/arch/powerpc/kernel/kgdb.c
> +++ b/arch/powerpc/kernel/kgdb.c
> @@ -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

2013-03-10 19:05:27

by Daniel Baluta

[permalink] [raw]
Subject: Re: [PATCH] kgdb: Removed kmalloc returned value cast

On Sun, Mar 10, 2013 at 4:10 PM, Pekka Enberg <[email protected]> wrote:
> On Sun, Mar 10, 2013 at 3:06 PM, Alex Grad <[email protected]> wrote:
>> Signed-off-by: Alex Grad <[email protected]>
>> ---
>> arch/powerpc/kernel/kgdb.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
>> index 5ca82cd..c1eef24 100644
>> --- a/arch/powerpc/kernel/kgdb.c
>> +++ b/arch/powerpc/kernel/kgdb.c
>> @@ -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.

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.