linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [TRIVIAL] kstrdup
@ 2003-04-18  7:58 Rusty Trivial Russell
  2003-04-18  8:10 ` Jeff Garzik
  0 siblings, 1 reply; 20+ messages in thread
From: Rusty Trivial Russell @ 2003-04-18  7:58 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

From:  Rusty Russell <rusty@rustcorp.com.au>

  Everyone loves reimplementing strdup.  Give them a kstrdup (basically
  from drivers/md).
  
  Rusty.
  --
    Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
  
  Name: kstrdup
  Author: Neil Brown and Rusty Russell
  Status: Trivial
  
  D: Everyone loves reimplementing strdup.  Give them a kstrdup.
  

--- trivial-2.5.67-bk8/drivers/md/dm-ioctl.c.orig	2003-04-18 17:43:57.000000000 +1000
+++ trivial-2.5.67-bk8/drivers/md/dm-ioctl.c	2003-04-18 17:43:57.000000000 +1000
@@ -14,6 +14,7 @@
 #include <linux/wait.h>
 #include <linux/blk.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 
 #include <asm/uaccess.h>
 
@@ -118,14 +119,6 @@
 /*-----------------------------------------------------------------
  * Inserting, removing and renaming a device.
  *---------------------------------------------------------------*/
-static inline char *kstrdup(const char *str)
-{
-	char *r = kmalloc(strlen(str) + 1, GFP_KERNEL);
-	if (r)
-		strcpy(r, str);
-	return r;
-}
-
 static struct hash_cell *alloc_cell(const char *name, const char *uuid,
 				    struct mapped_device *md)
 {
@@ -135,7 +128,7 @@
 	if (!hc)
 		return NULL;
 
-	hc->name = kstrdup(name);
+	hc->name = kstrdup(name, GFP_KERNEL);
 	if (!hc->name) {
 		kfree(hc);
 		return NULL;
@@ -145,7 +138,7 @@
 		hc->uuid = NULL;
 
 	else {
-		hc->uuid = kstrdup(uuid);
+		hc->uuid = kstrdup(uuid, GFP_KERNEL);
 		if (!hc->uuid) {
 			kfree(hc->name);
 			kfree(hc);
@@ -270,7 +263,7 @@
 	/*
 	 * duplicate new.
 	 */
-	new_name = kstrdup(new);
+	new_name = kstrdup(new, GFP_KERNEL);
 	if (!new_name)
 		return -ENOMEM;
 
--- trivial-2.5.67-bk8/include/linux/string.h.orig	2003-04-18 17:43:57.000000000 +1000
+++ trivial-2.5.67-bk8/include/linux/string.h	2003-04-18 17:43:57.000000000 +1000
@@ -78,6 +78,8 @@
 extern void * memchr(const void *,int,__kernel_size_t);
 #endif
 
+extern char *kstrdup(const char *s, int gfp);
+
 #ifdef __cplusplus
 }
 #endif
--- trivial-2.5.67-bk8/kernel/ksyms.c.orig	2003-04-18 17:43:57.000000000 +1000
+++ trivial-2.5.67-bk8/kernel/ksyms.c	2003-04-18 17:43:57.000000000 +1000
@@ -585,6 +585,7 @@
 EXPORT_SYMBOL(strnicmp);
 EXPORT_SYMBOL(strspn);
 EXPORT_SYMBOL(strsep);
+EXPORT_SYMBOL(kstrdup);
 
 /* software interrupts */
 EXPORT_SYMBOL(tasklet_init);
--- trivial-2.5.67-bk8/lib/string.c.orig	2003-04-18 17:43:57.000000000 +1000
+++ trivial-2.5.67-bk8/lib/string.c	2003-04-18 17:43:57.000000000 +1000
@@ -22,6 +22,7 @@
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
+#include <linux/slab.h>
 
 #ifndef __HAVE_ARCH_STRNICMP
 /**
@@ -525,5 +526,12 @@
 	}
 	return NULL;
 }
-
 #endif
+
+char *kstrdup(const char *s, int gfp)
+{
+	char *buf = kmalloc(strlen(s)+1, gfp);
+	if (buf)
+		strcpy(buf, s);
+	return buf;
+}
-- 
  Don't blame me: the Monkey is driving
  File: Rusty Russell <rusty@rustcorp.com.au>: [PATCH] [TRIVIAL] kstrdup

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2003-04-20  8:00 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-18  7:58 [TRIVIAL] kstrdup Rusty Trivial Russell
2003-04-18  8:10 ` Jeff Garzik
2003-04-18 16:20   ` Linus Torvalds
2003-04-18 16:56     ` Jeff Garzik
2003-04-18 18:00       ` Linus Torvalds
2003-04-18 18:44         ` Jeff Garzik
2003-04-19  4:52         ` Rusty Russell
2003-04-18 18:00       ` Richard B. Johnson
2003-04-18 18:40         ` Jeff Garzik
2003-04-18 19:24           ` H. Peter Anvin
2003-04-18 23:37             ` Alan Cox
2003-04-18 19:29           ` Richard B. Johnson
2003-04-19 11:45             ` Kai Henningsen
2003-04-19 20:16             ` Ruth Ivimey-Cook
2003-04-19  4:14   ` Rusty Russell
2003-04-19  4:48     ` Jeff Garzik
2003-04-19  8:28       ` Rusty Russell
2003-04-19 12:27       ` Alan Cox
2003-04-19 14:44         ` Bernd Eckenfels
2003-04-20  8:05         ` Rusty Russell

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