* [PATCH 3/3] fs/jffs2/dir.c: Use kasprintf
[not found] <1287341311-11161-1-git-send-email-julia@diku.dk>
@ 2010-10-17 18:48 ` Julia Lawall
[not found] ` <1287341849.20968.62.camel@Joe-Laptop>
0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2010-10-17 18:48 UTC (permalink / raw)
To: David Woodhouse; +Cc: linux-mtd, kernel-janitors, linux-kernel
Convert a sequence of kmalloc and memcpy to use kasprintf. The argument is
checked for being a string by the presence of a previous call to strlen.
The semantic patch that performs this transformation is:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression a,flag,len;
expression arg,e1,e2;
statement S;
@@
len = strlen(arg)
... when != len = e1
when != arg = e2
a =
- \(kmalloc\|kzalloc\)(len+1,flag)
+ kasprintf(flag,"%s",arg)
<... when != a
if (a == NULL || ...) S
...>
- memcpy(a,arg,len+1);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
fs/jffs2/dir.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index ed78a3c..8ee5675 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -367,7 +367,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
}
/* We use f->target field to store the target path. */
- f->target = kmalloc(targetlen + 1, GFP_KERNEL);
+ f->target = kasprintf(GFP_KERNEL, "%s", target);
if (!f->target) {
printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
mutex_unlock(&f->sem);
@@ -376,7 +376,6 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
goto fail;
}
- memcpy(f->target, target, targetlen + 1);
D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->target));
/* No data here. Only a metadata node, which will be
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] fs/jffs2/dir.c: Use kmemdup
[not found] ` <1287341849.20968.62.camel@Joe-Laptop>
@ 2010-10-17 19:56 ` Julia Lawall
2010-10-18 3:43 ` Artem Bityutskiy
0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2010-10-17 19:56 UTC (permalink / raw)
To: Joe Perches; +Cc: linux-mtd, David Woodhouse, linux-kernel
Convert a sequence of kmalloc and memcpy to use kmemdup.
The semantic patch that performs this transformation is:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression a,flag,len;
expression arg,e1,e2;
statement S;
@@
a =
- \(kmalloc\|kzalloc\)(len,flag)
+ kmemdup(arg,len,flag)
<... when != a
if (a == NULL || ...) S
...>
- memcpy(a,arg,len+1);
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
fs/jffs2/dir.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff -u -p a/fs/jffs2/dir.c b/fs/jffs2/dir.c
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -367,7 +367,7 @@ static int jffs2_symlink (struct inode *
}
/* We use f->target field to store the target path. */
- f->target = kmalloc(targetlen + 1, GFP_KERNEL);
+ f->target = kmemdup(target, targetlen + 1, GFP_KERNEL);
if (!f->target) {
printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
mutex_unlock(&f->sem);
@@ -376,7 +376,6 @@ static int jffs2_symlink (struct inode *
goto fail;
}
- memcpy(f->target, target, targetlen + 1);
D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->target));
/* No data here. Only a metadata node, which will be
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 3/3] fs/jffs2/dir.c: Use kmemdup
2010-10-17 19:56 ` [PATCH 3/3] fs/jffs2/dir.c: Use kmemdup Julia Lawall
@ 2010-10-18 3:43 ` Artem Bityutskiy
0 siblings, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2010-10-18 3:43 UTC (permalink / raw)
To: Julia Lawall; +Cc: Joe Perches, linux-mtd, David Woodhouse, linux-kernel
On Sun, 2010-10-17 at 21:56 +0200, Julia Lawall wrote:
> Convert a sequence of kmalloc and memcpy to use kmemdup.
>
> The semantic patch that performs this transformation is:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression a,flag,len;
> expression arg,e1,e2;
> statement S;
> @@
>
> a =
> - \(kmalloc\|kzalloc\)(len,flag)
> + kmemdup(arg,len,flag)
> <... when != a
> if (a == NULL || ...) S
> ...>
> - memcpy(a,arg,len+1);
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
>
> ---
> fs/jffs2/dir.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Picked this one and put to l2-mtd-2.6.git, thanks.
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-10-18 3:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1287341311-11161-1-git-send-email-julia@diku.dk>
2010-10-17 18:48 ` [PATCH 3/3] fs/jffs2/dir.c: Use kasprintf Julia Lawall
[not found] ` <1287341849.20968.62.camel@Joe-Laptop>
2010-10-17 19:56 ` [PATCH 3/3] fs/jffs2/dir.c: Use kmemdup Julia Lawall
2010-10-18 3:43 ` Artem Bityutskiy
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).