* [PATCH 1/10] drivers/s390/char: Use kstrdup
@ 2010-05-14 19:28 Julia Lawall
2010-05-14 20:10 ` Julia Lawall
0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2010-05-14 19:28 UTC (permalink / raw)
To: Martin Schwidefsky, Heiko Carstens, linux390, linux-s390,
linux-kernel, kernel-janitors
From: Julia Lawall <julia@diku.dk>
Use kstrdup when the goal of an allocation is copy a string into the
allocated region.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x,from,to;
expression flag,E1,E2,E3;
statement S;
@@
- x = strlen(from) + 1;
... when != \( x = E1 \| from = E1 \)
- to = \(kmalloc\|kzalloc\)(x,flag);
+ to = kstrdup(from, flag);
... when != \(x = E2 \| from = E2 \| to = E2 \)
if (to==NULL || ...) S
... when != \(x = E3 \| from = E3 \| to = E3 \)
- memcpy(to, from, x);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/s390/char/keyboard.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff -u -p a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -72,11 +72,10 @@ kbd_alloc(void) {
goto out_maps;
for (i = 0; i < ARRAY_SIZE(func_table); i++) {
if (func_table[i]) {
- len = strlen(func_table[i]) + 1;
- kbd->func_table[i] = kmalloc(len, GFP_KERNEL);
+ kbd->func_table[i] = kstrdup(func_table[i],
+ GFP_KERNEL);
if (!kbd->func_table[i])
goto out_func;
- memcpy(kbd->func_table[i], func_table[i], len);
}
}
kbd->fn_handler =
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/10] drivers/s390/char: Use kstrdup
2010-05-14 19:28 [PATCH 1/10] drivers/s390/char: Use kstrdup Julia Lawall
@ 2010-05-14 20:10 ` Julia Lawall
2010-05-14 21:03 ` Julia Lawall
0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2010-05-14 20:10 UTC (permalink / raw)
To: Martin Schwidefsky, Heiko Carstens, linux390, linux-s390,
linux-kernel, kernel-janitors
This introduced an unused variable. I will send a revised version
shortly.
julia
On Fri, 14 May 2010, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> Use kstrdup when the goal of an allocation is copy a string into the
> allocated region.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x,from,to;
> expression flag,E1,E2,E3;
> statement S;
> @@
>
> - x = strlen(from) + 1;
> ... when != \( x = E1 \| from = E1 \)
> - to = \(kmalloc\|kzalloc\)(x,flag);
> + to = kstrdup(from, flag);
> ... when != \(x = E2 \| from = E2 \| to = E2 \)
> if (to==NULL || ...) S
> ... when != \(x = E3 \| from = E3 \| to = E3 \)
> - memcpy(to, from, x);
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
>
> ---
> drivers/s390/char/keyboard.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff -u -p a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
> --- a/drivers/s390/char/keyboard.c
> +++ b/drivers/s390/char/keyboard.c
> @@ -72,11 +72,10 @@ kbd_alloc(void) {
> goto out_maps;
> for (i = 0; i < ARRAY_SIZE(func_table); i++) {
> if (func_table[i]) {
> - len = strlen(func_table[i]) + 1;
> - kbd->func_table[i] = kmalloc(len, GFP_KERNEL);
> + kbd->func_table[i] = kstrdup(func_table[i],
> + GFP_KERNEL);
> if (!kbd->func_table[i])
> goto out_func;
> - memcpy(kbd->func_table[i], func_table[i], len);
> }
> }
> kbd->fn_handler =
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/10] drivers/s390/char: Use kstrdup
2010-05-14 20:10 ` Julia Lawall
@ 2010-05-14 21:03 ` Julia Lawall
2010-05-17 10:23 ` Martin Schwidefsky
0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2010-05-14 21:03 UTC (permalink / raw)
To: Martin Schwidefsky, Heiko Carstens, linux390, linux-s390,
linux-kernel, kernel-janitors
From: Julia Lawall <julia@diku.dk>
Use kstrdup when the goal of an allocation is copy a string into the
allocated region. Additionally drop the now unused variable len.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression from,to;
expression flag,E1,E2;
statement S;
@@
- to = kmalloc(strlen(from) + 1,flag);
+ to = kstrdup(from, flag);
... when != \(from = E1 \| to = E1 \)
if (to==NULL || ...) S
... when != \(from = E2 \| to = E2 \)
- strcpy(to, from);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/s390/char/keyboard.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff -u -p a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -49,7 +49,7 @@ static unsigned char ret_diacr[NR_DEAD]
struct kbd_data *
kbd_alloc(void) {
struct kbd_data *kbd;
- int i, len;
+ int i;
kbd = kzalloc(sizeof(struct kbd_data), GFP_KERNEL);
if (!kbd)
@@ -72,11 +72,10 @@ kbd_alloc(void) {
goto out_maps;
for (i = 0; i < ARRAY_SIZE(func_table); i++) {
if (func_table[i]) {
- len = strlen(func_table[i]) + 1;
- kbd->func_table[i] = kmalloc(len, GFP_KERNEL);
+ kbd->func_table[i] = kstrdup(func_table[i],
+ GFP_KERNEL);
if (!kbd->func_table[i])
goto out_func;
- memcpy(kbd->func_table[i], func_table[i], len);
}
}
kbd->fn_handler =
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/10] drivers/s390/char: Use kstrdup
2010-05-14 21:03 ` Julia Lawall
@ 2010-05-17 10:23 ` Martin Schwidefsky
0 siblings, 0 replies; 4+ messages in thread
From: Martin Schwidefsky @ 2010-05-17 10:23 UTC (permalink / raw)
To: Julia Lawall
Cc: Heiko Carstens, linux390, linux-s390, linux-kernel, kernel-janitors
On Fri, 14 May 2010 23:03:51 +0200 (CEST)
Julia Lawall <julia@diku.dk> wrote:
> From: Julia Lawall <julia@diku.dk>
>
> Use kstrdup when the goal of an allocation is copy a string into the
> allocated region. Additionally drop the now unused variable len.
>
> The semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression from,to;
> expression flag,E1,E2;
> statement S;
> @@
>
> - to = kmalloc(strlen(from) + 1,flag);
> + to = kstrdup(from, flag);
> ... when != \(from = E1 \| to = E1 \)
> if (to==NULL || ...) S
> ... when != \(from = E2 \| to = E2 \)
> - strcpy(to, from);
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
Added to git390, thanks Julia.
--
blue skies,
Martin.
"Reality continues to ruin my life." - Calvin.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-17 10:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-14 19:28 [PATCH 1/10] drivers/s390/char: Use kstrdup Julia Lawall
2010-05-14 20:10 ` Julia Lawall
2010-05-14 21:03 ` Julia Lawall
2010-05-17 10:23 ` Martin Schwidefsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®