[...]
+static char *strdup(const char *str)
+{
+ char *s;
+
+ if (!str)
+ return NULL;
+ s = kmalloc(strlen(str)+1, GFP_KERNEL);
+ if (!s)
+ return NULL;
+ strcpy(s, str);
+ return s;
+}
+
There is already this code in sound/core/memory.c:
char *snd_kmalloc_strdup(const char *string, int flags) { size_t len; char *ptr;
if (!string) return NULL; len = strlen(string) + 1; ptr = _snd_kmalloc(len, flags); if (ptr) memcpy(ptr, string, len); return ptr; }
and grep'ing the includes for "strdup" gives this:
./linux/netdevice.h:extern char *net_sysctl_strdup(const char *s); ./linux/parser.h:char *match_strdup(substring_t *); ./sound/core.h:char *snd_kmalloc_strdup(const char *string, int flags);
Actually, I've just grep'ed the entire tree and there are about 7 similar implementations all over the place:
./arch/um/kernel/process_kern.c:char *uml_strdup(char *string)
./drivers/parport/probe.c:static char *strdup(char *str)
./drivers/md/dm-ioctl.c:static inline char *kstrdup(const char *str)
./net/core/sysctl_net_core.c:char *net_sysctl_strdup(const char *s)
./net/sunrpc/svcauth_unix.c:static char *strdup(char *s)
./sound/core/memory.c:char *snd_kmalloc_strdup(const char *string, int flags)
./lib/parser.c:char *match_strdup(substring_t *s)
So maybe we should turn this into a library function and modify the callers, so that we have only one implementation. The implementation from sound/core seems better for a library function, because of the flags argument (and it seems a little more eficient too).
-- Paulo Marques - www.grupopie.com
"A journey of a thousand miles begins with a single step." Lao-tzu, The Way of Lao-tzu
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/