2007-11-05 02:17:27

by Li Zefan

[permalink] [raw]
Subject: [PATCH 1/6] ARM: fix memset size error

The size passing to memset is wrong. And here we can replace
kmalloc with kzalloc.

Signed-off-by Li Zefan <[email protected]>

---
arch/arm/common/uengine.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/arm/common/uengine.c b/arch/arm/common/uengine.c
index 95c8508..117cab3 100644
--- a/arch/arm/common/uengine.c
+++ b/arch/arm/common/uengine.c
@@ -374,8 +374,8 @@ static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
u8 *ucode;
int i;

- gpr_a = kmalloc(128 * sizeof(u32), GFP_KERNEL);
- gpr_b = kmalloc(128 * sizeof(u32), GFP_KERNEL);
+ gpr_a = kzalloc(128 * sizeof(u32), GFP_KERNEL);
+ gpr_b = kzalloc(128 * sizeof(u32), GFP_KERNEL);
ucode = kmalloc(513 * 5, GFP_KERNEL);
if (gpr_a == NULL || gpr_b == NULL || ucode == NULL) {
kfree(ucode);
@@ -388,8 +388,6 @@ static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
if (c->uengine_parameters & IXP2000_UENGINE_4_CONTEXTS)
per_ctx_regs = 32;

- memset(gpr_a, 0, sizeof(gpr_a));
- memset(gpr_b, 0, sizeof(gpr_b));
for (i = 0; i < 256; i++) {
struct ixp2000_reg_value *r = c->initial_reg_values + i;
u32 *bank;
--
1.5.3.rc7


2007-11-05 04:08:14

by Robert P. J. Day

[permalink] [raw]
Subject: Re: [PATCH 1/6] ARM: fix memset size error

On Mon, 5 Nov 2007, Li Zefan wrote:

> The size passing to memset is wrong. And here we can replace
> kmalloc with kzalloc.
>
> Signed-off-by Li Zefan <[email protected]>
>
> ---
> arch/arm/common/uengine.c | 6 ++----
> 1 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm/common/uengine.c b/arch/arm/common/uengine.c
> index 95c8508..117cab3 100644
> --- a/arch/arm/common/uengine.c
> +++ b/arch/arm/common/uengine.c
> @@ -374,8 +374,8 @@ static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
> u8 *ucode;
> int i;
>
> - gpr_a = kmalloc(128 * sizeof(u32), GFP_KERNEL);
> - gpr_b = kmalloc(128 * sizeof(u32), GFP_KERNEL);
> + gpr_a = kzalloc(128 * sizeof(u32), GFP_KERNEL);
> + gpr_b = kzalloc(128 * sizeof(u32), GFP_KERNEL);
> ucode = kmalloc(513 * 5, GFP_KERNEL);
> if (gpr_a == NULL || gpr_b == NULL || ucode == NULL) {
> kfree(ucode);
> @@ -388,8 +388,6 @@ static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
> if (c->uengine_parameters & IXP2000_UENGINE_4_CONTEXTS)
> per_ctx_regs = 32;
>
> - memset(gpr_a, 0, sizeof(gpr_a));
> - memset(gpr_b, 0, sizeof(gpr_b));
> for (i = 0; i < 256; i++) {
> struct ixp2000_reg_value *r = c->initial_reg_values + i;
> u32 *bank;
>
it's unlikely that patch will cause any trouble whatsoever, but
notice that it *is* changing the underlying logic. those original
memsets should probably have been written initially as
"sizeof(*gpr_a)" so they would previously have zeroed only memory the
^
size of a pointer, no?

now, i'm guessing the logic is correct but i figured it's worth
noting what the code *used* to do. unless i'm misreading something
horribly.



rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

2007-11-05 05:11:55

by Li Zefan

[permalink] [raw]
Subject: Re: [PATCH 1/6] ARM: fix memset size error

Robert P. J. Day wrote:
> On Mon, 5 Nov 2007, Li Zefan wrote:
>
>> The size passing to memset is wrong. And here we can replace
>> kmalloc with kzalloc.
>>
>> Signed-off-by Li Zefan <[email protected]>
>>
>> ---
>> arch/arm/common/uengine.c | 6 ++----
>> 1 files changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/arm/common/uengine.c b/arch/arm/common/uengine.c
>> index 95c8508..117cab3 100644
>> --- a/arch/arm/common/uengine.c
>> +++ b/arch/arm/common/uengine.c
>> @@ -374,8 +374,8 @@ static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
>> u8 *ucode;
>> int i;
>>
>> - gpr_a = kmalloc(128 * sizeof(u32), GFP_KERNEL);
>> - gpr_b = kmalloc(128 * sizeof(u32), GFP_KERNEL);
>> + gpr_a = kzalloc(128 * sizeof(u32), GFP_KERNEL);
>> + gpr_b = kzalloc(128 * sizeof(u32), GFP_KERNEL);
>> ucode = kmalloc(513 * 5, GFP_KERNEL);
>> if (gpr_a == NULL || gpr_b == NULL || ucode == NULL) {
>> kfree(ucode);
>> @@ -388,8 +388,6 @@ static int set_initial_registers(int uengine, struct ixp2000_uengine_code *c)
>> if (c->uengine_parameters & IXP2000_UENGINE_4_CONTEXTS)
>> per_ctx_regs = 32;
>>
>> - memset(gpr_a, 0, sizeof(gpr_a));
>> - memset(gpr_b, 0, sizeof(gpr_b));
>> for (i = 0; i < 256; i++) {
>> struct ixp2000_reg_value *r = c->initial_reg_values + i;
>> u32 *bank;
>>
> it's unlikely that patch will cause any trouble whatsoever, but
> notice that it *is* changing the underlying logic. those original
> memsets should probably have been written initially as
> "sizeof(*gpr_a)" so they would previously have zeroed only memory the
> ^
> size of a pointer, no?
>
> now, i'm guessing the logic is correct but i figured it's worth
> noting what the code *used* to do. unless i'm misreading something
> horribly.
>

In the for loop, some elems of gpr_a and gpr_b will be assigned with a value,
but not all elems. So those unassigned elems should be filled with 0.

I think it happens now and then to mistake to regard a pointer as a static
array, and I guess this is what sizeof(gpr_a) means.

Li Zefan