Skip to contentSkip to conversation

staging/lustre/libcfs: replaced string duplication code with kstrdup

PATCH In review Dragos Foianu 2 participants 2 messages Jul 12, 2013 – Jul 14, 2013 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging/lustre/libcfs: replaced string duplication code with kstrdup

Modified cfs_strdup function to use kstrdup instead of duplicating its implementation.

Found using Coccinelle.

---
 drivers/staging/lustre/lustre/libcfs/libcfs_string.c |   13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/staging/lustre/lustre/libcfs/libcfs_string.c +1 -12
index 9edccc9..4dba304 100644
@@ -135,18 +135,7 @@ EXPORT_SYMBOL(cfs_str2mask);
 /* Duplicate a string in a platform-independent way */
 char *cfs_strdup(const char *str, u_int32_t flags)
 {
-	size_t lenz; /* length of str + zero byte */
-	char *dup_str;
-
-	lenz = strlen(str) + 1;
-
-	dup_str = kmalloc(lenz, flags);
-	if (dup_str == NULL)
-		return NULL;
-
-	memcpy(dup_str, str, lenz);
-
-	return dup_str;
+	return kstrdup(str, flags);
 }
 EXPORT_SYMBOL(cfs_strdup);
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · Dragos Foianu

Modified cfs_strdup function to use kstrdup instead of duplicating its implementation.

Found using Coccinelle.

Thanks for the patch, but in fact this function doesn't appear to be used in the code anymore and could be removed entirely. Seems that cfs_vsnprintf() and cfs_snprintf() could also be deleted at the same time.

Cheers, Andreas

Quoted 19 lines

---
drivers/staging/lustre/lustre/libcfs/libcfs_string.c | 13 +------------

1 file changed, 1 insertion(+), 12 deletions(-)
drivers/staging/lustre/lustre/libcfs/libcfs_string.c +0 -5
index 9edccc9..4dba304 100644
@@ -135,18 +135,7 @@ EXPORT_SYMBOL(cfs_str2mask);
 /* Duplicate a string in a platform-independent way */
 char *cfs_strdup(const char *str, u_int32_t flags)
 {
-	size_t lenz; /* length of str + zero byte */
-	char *dup_str;
-
-	lenz = strlen(str) + 1;
-

drivers/staging/lustre/lustre/libcfs/libcfs_string.c EXPORT_SYMBOL(cfs_str2mask); · line 140

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/libcfs_string.c +1 -7
-	dup_str = kmalloc(lenz, flags);
-	if (dup_str == NULL)
-		return NULL;
-
-	memcpy(dup_str, str, lenz);
-
-	return dup_str;
+	return kstrdup(str, flags);
 }
 EXPORT_SYMBOL(cfs_strdup);

Cheers, Andreas

Signature · 4 lines
Andreas Dilger

Lustre Software Architect
Intel High Performance Data Division