From: Rusty Russell <rusty@rustcorp.com.au>
To: linux-kernel@vger.kernel.org
Cc: torvalds@transmeta.com, trivial@rustcorp.com.au,
Neil Brown <neilb@cse.unsw.edu.au>,
dwmw2@redhat.com
Subject: [PATCH] [TRIVIAL] kstrdup
Date: Tue, 14 Jan 2003 12:55:40 +1100 [thread overview]
Message-ID: <20030114025452.656612C385@lists.samba.org> (raw)
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.
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/drivers/md/dm-ioctl.c working-2.5-bk-kstrdup/drivers/md/dm-ioctl.c
--- linux-2.5-bk/drivers/md/dm-ioctl.c 2003-01-02 12:47:01.000000000 +1100
+++ working-2.5-bk-kstrdup/drivers/md/dm-ioctl.c 2003-01-06 15:47:26.000000000 +1100
@@ -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 @@ static struct hash_cell *__get_uuid_cell
/*-----------------------------------------------------------------
* 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 @@ static struct hash_cell *alloc_cell(cons
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 @@ static struct hash_cell *alloc_cell(cons
hc->uuid = NULL;
else {
- hc->uuid = kstrdup(uuid);
+ hc->uuid = kstrdup(uuid, GFP_KERNEL);
if (!hc->uuid) {
kfree(hc->name);
kfree(hc);
@@ -266,7 +259,7 @@ int dm_hash_rename(const char *old, cons
/*
* duplicate new.
*/
- new_name = kstrdup(new);
+ new_name = kstrdup(new, GFP_KERNEL);
if (!new_name)
return -ENOMEM;
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/include/linux/string.h working-2.5-bk-kstrdup/include/linux/string.h
--- linux-2.5-bk/include/linux/string.h 2003-01-02 12:35:15.000000000 +1100
+++ working-2.5-bk-kstrdup/include/linux/string.h 2003-01-06 15:48:24.000000000 +1100
@@ -78,6 +78,8 @@ extern int memcmp(const void *,const voi
extern void * memchr(const void *,int,__kernel_size_t);
#endif
+extern char *kstrdup(const char *s, int gfp);
+
#ifdef __cplusplus
}
#endif
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/kernel/ksyms.c working-2.5-bk-kstrdup/kernel/ksyms.c
--- linux-2.5-bk/kernel/ksyms.c 2003-01-02 14:48:01.000000000 +1100
+++ working-2.5-bk-kstrdup/kernel/ksyms.c 2003-01-06 15:49:30.000000000 +1100
@@ -577,6 +577,7 @@ EXPORT_SYMBOL(get_write_access);
EXPORT_SYMBOL(strnicmp);
EXPORT_SYMBOL(strspn);
EXPORT_SYMBOL(strsep);
+EXPORT_SYMBOL(kstrdup);
/* software interrupts */
EXPORT_SYMBOL(tasklet_init);
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5-bk/lib/string.c working-2.5-bk-kstrdup/lib/string.c
--- linux-2.5-bk/lib/string.c 2003-01-02 12:35:15.000000000 +1100
+++ working-2.5-bk-kstrdup/lib/string.c 2003-01-06 15:48:57.000000000 +1100
@@ -525,5 +525,12 @@ void *memchr(const void *s, int c, size_
}
return NULL;
}
-
#endif
+
+char *kstrdup(const char *s, int gfp)
+{
+ char *buf = kmalloc(strlen(s)+1, gfp);
+ if (buf)
+ strcpy(buf, s);
+ return buf;
+}
next reply other threads:[~2003-01-14 2:47 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-14 1:55 Rusty Russell [this message]
2003-01-14 3:19 ` [PATCH] [TRIVIAL] kstrdup Jeff Garzik
2003-01-15 6:45 ` Rusty Russell
2003-01-14 3:28 ` Valdis.Kletnieks
2003-01-14 3:38 ` Jeff Garzik
2003-01-14 3:53 ` Valdis.Kletnieks
2003-01-14 4:15 ` Jeff Garzik
2003-01-14 5:15 ` Valdis.Kletnieks
2003-01-14 11:48 ` Olaf Dietsche
2003-01-15 6:55 ` Rusty Russell
2003-01-19 23:37 ` Pavel Machek
2003-01-22 2:04 ` Rusty Russell
2003-01-23 14:02 ` Pavel Machek
2003-01-23 14:21 ` Martin Mares
2003-01-23 14:44 ` Pavel Machek
2003-01-29 4:51 ` Rusty Russell
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=20030114025452.656612C385@lists.samba.org \
--to=rusty@rustcorp.com.au \
--cc=dwmw2@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=neilb@cse.unsw.edu.au \
--cc=torvalds@transmeta.com \
--cc=trivial@rustcorp.com.au \
/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.