All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia@diku.dk>
To: Sage Weil <sage@newdream.net>
Cc: kernel-janitors@vger.kernel.org, ceph-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] fs/ceph/xattr.c: Use kasprintf
Date: Sun, 17 Oct 2010 20:48:30 +0200	[thread overview]
Message-ID: <1287341311-11161-3-git-send-email-julia@diku.dk> (raw)
In-Reply-To: <1287341311-11161-1-git-send-email-julia@diku.dk>

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/ceph/xattr.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 70e9199..b8dd1f0 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -716,10 +716,9 @@ int ceph_setxattr(struct dentry *dentry, const char *name,
 
 	/* preallocate memory for xattr name, value, index node */
 	err = -ENOMEM;
-	newname = kmalloc(name_len + 1, GFP_NOFS);
+	newname = kasprintf(GFP_NOFS, "%s", name);
 	if (!newname)
 		goto out;
-	memcpy(newname, name, name_len + 1);
 
 	if (val_len) {
 		newval = kmalloc(val_len + 1, GFP_NOFS);


WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia@diku.dk>
To: Sage Weil <sage@newdream.net>
Cc: kernel-janitors@vger.kernel.org, ceph-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] fs/ceph/xattr.c: Use kasprintf
Date: Sun, 17 Oct 2010 18:48:30 +0000	[thread overview]
Message-ID: <1287341311-11161-3-git-send-email-julia@diku.dk> (raw)
In-Reply-To: <1287341311-11161-1-git-send-email-julia@diku.dk>

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/ceph/xattr.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 70e9199..b8dd1f0 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -716,10 +716,9 @@ int ceph_setxattr(struct dentry *dentry, const char *name,
 
 	/* preallocate memory for xattr name, value, index node */
 	err = -ENOMEM;
-	newname = kmalloc(name_len + 1, GFP_NOFS);
+	newname = kasprintf(GFP_NOFS, "%s", name);
 	if (!newname)
 		goto out;
-	memcpy(newname, name, name_len + 1);
 
 	if (val_len) {
 		newval = kmalloc(val_len + 1, GFP_NOFS);


  parent reply	other threads:[~2010-10-17 18:42 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-17 18:48 [PATCH 0/3] Use kasprintf Julia Lawall
2010-10-17 18:48 ` Julia Lawall
2010-10-17 18:48 ` [PATCH 1/3] drivers/staging/cx25821: " Julia Lawall
2010-10-17 18:48   ` Julia Lawall
2010-10-18  7:15   ` walter harms
2010-10-18  7:15     ` walter harms
2010-10-18  8:22     ` Julia Lawall
2010-10-18  8:22       ` Julia Lawall
2010-10-18  9:27       ` walter harms
2010-10-18  9:27         ` walter harms
2010-10-18 12:25         ` [PATCH 1/3] drivers/staging/cx25821: Use kstrdup Julia Lawall
2010-10-18 12:25           ` Julia Lawall
2010-10-18 17:38           ` Joe Perches
2010-10-18 17:38             ` Joe Perches
2010-10-18 17:44             ` Julia Lawall
2010-10-18 17:44               ` Julia Lawall
2010-10-18 17:55               ` Joe Perches
2010-10-18 17:55                 ` Joe Perches
2010-10-18 17:58                 ` Julia Lawall
2010-10-18 17:58                   ` Julia Lawall
2010-10-18 20:43             ` Julia Lawall
2010-10-18 20:43               ` Julia Lawall
2010-10-17 18:48 ` Julia Lawall [this message]
2010-10-17 18:48   ` [PATCH 2/3] fs/ceph/xattr.c: Use kasprintf Julia Lawall
2010-10-17 18:54   ` Joe Perches
2010-10-17 18:54     ` Joe Perches
2010-10-17 19:02     ` Julia Lawall
2010-10-17 19:02       ` Julia Lawall
2010-10-17 19:55     ` [PATCH 2/3] fs/ceph/xattr.c: Use kmemdup Julia Lawall
2010-10-17 19:55       ` Julia Lawall
2010-10-17 21:36       ` Sage Weil
2010-10-17 21:36         ` Sage Weil
2010-10-17 18:48 ` [PATCH 3/3] fs/jffs2/dir.c: Use kasprintf Julia Lawall
2010-10-17 18:48   ` Julia Lawall
2010-10-17 18:48   ` 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-17 19:56       ` Julia Lawall
2010-10-18  3:43       ` Artem Bityutskiy
2010-10-18  3:43         ` Artem Bityutskiy
2010-10-18 18:09 ` [PATCH 0/3] Use kasprintf Paulo Marques
2010-10-18 18:09   ` Paulo Marques
2010-10-18 20:02   ` Julia Lawall
2010-10-18 20:02     ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1287341311-11161-3-git-send-email-julia@diku.dk \
    --to=julia@diku.dk \
    --cc=ceph-devel@vger.kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sage@newdream.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.