Skip to contentSkip to conversation

lustre:libcfs: remove redundant code.

PATCH In review Alexandru Juncu 6 participants 11 messages Jul 19, 2013 – Jul 22, 2013 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lustre:libcfs: remove redundant code.

Found using coccinelle. It suggested kmalloc/strcpy should be replaced with kstrdup, but the entire function can be replaced by kstrdup.

---
 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.8.1.2
#1 lore raw
Quoted 21 lines · Alexandru Juncu

Found using coccinelle. It suggested kmalloc/strcpy should be replaced with kstrdup, but the entire function can be replaced by kstrdup.

---
 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);

It would be better if you replaced the calls to cfs_strdup() with kstrdup() and got rid of cfs_strdup() altogether.

#2 lore raw
Quoted 27 lines · Pekka Enberg
Quoted 26 lines · Alexandru Juncu

Found using coccinelle. It suggested kmalloc/strcpy should be replaced with kstrdup, but the entire function can be replaced by kstrdup.

---
 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 -10
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);
Quoted 8 lines

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

Quoted 5 lines
drivers/staging/lustre/lustre/libcfs/libcfs_string.c +1 -2
-
-       return dup_str;
+       return kstrdup(str, flags);
 }
 EXPORT_SYMBOL(cfs_strdup);

It would be better if you replaced the calls to cfs_strdup() with kstrdup() and got rid of cfs_strdup() altogether.

I was thinking the same thing, but I hesitated because I didn't know how used it was and I didn't want to break something.

#3 lore raw
Quoted 2 lines · Alexandru Juncu

I was thinking the same thing, but I hesitated because I didn't know how used it was and I didn't want to break something.

"git grep cfs_strdup" suggests that nobody uses it so you could just remove it completely...

#4 lore raw
Quoted 6 lines · Pekka Enberg
Quoted 2 lines · Alexandru Juncu

I was thinking the same thing, but I hesitated because I didn't know how used it was and I didn't want to break something.

"git grep cfs_strdup" suggests that nobody uses it so you could just remove it completely...

Did a grep on the tree and yes, it's not used. But It's in a staging directory so maybe the rest of the code has not been pushed in yet.

#5 lore raw
Quoted 10 lines · Alexandru Juncu
Quoted 6 lines · Pekka Enberg
Quoted 2 lines · Alexandru Juncu

I was thinking the same thing, but I hesitated because I didn't know how used it was and I didn't want to break something.

"git grep cfs_strdup" suggests that nobody uses it so you could just remove it completely...

Did a grep on the tree and yes, it's not used. But It's in a staging directory so maybe the rest of the code has not been pushed in yet.

Doesn't matter, if there are no users, please just remove it.

thanks,

greg k-h

#6 lore raw
Quoted 1 line · Greg Kroah-Hartman

Doesn't matter, if there are no users, please just remove it.

Is that, basically, your approach to staging cleanups?

I ask because I noticed that "drivers/staging/lustre/lustre/ptlrpc/gss/" is only built if CONFIG_PTLRPC_GSS is set. But the corresponding Kconfig symbol is nowhere to be found.

Or do you prefer that I poke the people involved in (this case in) Lustre before suggesting a drastic cleanup like that?

Paul Bolle

#7 lore raw
Quoted 11 lines · Paul Bolle
Quoted 1 line · Greg Kroah-Hartman

Doesn't matter, if there are no users, please just remove it.

Is that, basically, your approach to staging cleanups?

I ask because I noticed that "drivers/staging/lustre/lustre/ptlrpc/gss/" is only built if CONFIG_PTLRPC_GSS is set. But the corresponding Kconfig symbol is nowhere to be found.

Or do you prefer that I poke the people involved in (this case in) Lustre before suggesting a drastic cleanup like that?

Thanks for the comments!

The comment for that function is "Duplicate a string in a platform-independent way" so it might be because it's called by code that also run on non-Linux systems.

#8 lore raw
In reply to Paul Bolle
Quoted 7 lines

-----Original Message-----
From: Paul Bolle [mailto:[email protected]]
Sent: Saturday, July 20, 2013 12:07 AM
To: Greg Kroah-Hartman
Cc: Alexandru Juncu; Pekka Enberg; andreas.dilger; Peng, Tao; driverdev; LKML
Subject: Re: [PATCH] lustre:libcfs: remove redundant code.

Quoted 9 lines
Quoted 1 line · Greg Kroah-Hartman

Doesn't matter, if there are no users, please just remove it.

Is that, basically, your approach to staging cleanups?

I ask because I noticed that "drivers/staging/lustre/lustre/ptlrpc/gss/" is only built if CONFIG_PTLRPC_GSS is set. But the corresponding Kconfig symbol is nowhere to be found.

That's my fault. We certainly _want_ the ptlrpc gss code. I'll get it fixed.

Thanks,
Tao

Quoted 6 lines

Or do you prefer that I poke the people involved in (this case in) Lustre before suggesting a drastic cleanup like that?

Paul Bolle

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#9 lore raw
Quoted 6 lines · Tao

Paul Bolle [mailto:[email protected]]

Quoted 4 lines

I ask because I noticed that "drivers/staging/lustre/lustre/ptlrpc/gss/" is only built if CONFIG_PTLRPC_GSS is set. But the corresponding Kconfig symbol is nowhere to be found.

That's my fault. We certainly _want_ the ptlrpc gss code. I'll get it fixed.

I'll stop worrying about it. But if little has changed by, say, early 2014, I might try to prod you again.

Thanks!

Paul Bolle

#10 lore raw
In reply to Greg Kroah-Hartman
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Alexandru Juncu
Quoted 4 lines · Pekka Enberg
Quoted 2 lines · Alexandru Juncu

I was thinking the same thing, but I hesitated because I didn't know how used it was and I didn't want to break something.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

"git grep cfs_strdup" suggests that nobody uses it so you could just remove it completely...

Did a grep on the tree and yes, it's not used. But It's in a staging directory so maybe the rest of the code has not been pushed in yet.

Doesn't matter, if there are no users, please just remove it.

Hi Greg,

There is already a similar patch for this https://lkml.org/lkml/2013/7/17/742,
already reviewed by Andreas Dilger.

thanks,
Daniel.