All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paulo Marques <pmarques@grupopie.com>
To: Matt Domsch <Matt_Domsch@dell.com>
Cc: rusty@rustcorp.com.au, Greg KH <greg@kroah.com>,
	Christoph Hellwig <hch@infradead.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2.6.11-rc2] modules: add version and srcversion to sysfs
Date: Wed, 26 Jan 2005 14:32:22 +0000	[thread overview]
Message-ID: <41F7A9F6.20804@grupopie.com> (raw)
In-Reply-To: <20050126060541.GA16017@lists.us.dell.com>

Matt Domsch wrote:
> [...]
>  
> +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


  parent reply	other threads:[~2005-01-26 14:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-19 17:13 [PATCH] drop some attibutes from the FC transport class Christoph Hellwig
2005-01-19 17:21 ` Greg KH
2005-01-19 18:38   ` Brian King
2005-01-19 18:45     ` Greg KH
2005-01-19 22:59       ` Brian King
2005-01-19 21:39   ` Mike Anderson
2005-01-19 22:40     ` Greg KH
2005-01-19 23:03       ` Brian King
2005-01-19 23:03       ` Christoph Hellwig
2005-01-19 23:08         ` Greg KH
2005-01-19 23:15           ` Matt Domsch
2005-01-19 23:42             ` Greg KH
2005-01-20  5:12               ` Matt Domsch
2005-01-20 14:41                 ` Greg KH
2005-01-26  6:05               ` [PATCH 2.6.11-rc2] modules: add version and srcversion to sysfs Matt Domsch
2005-01-26  9:22                 ` Andreas Gruenbacher
2005-01-26 14:09                   ` Matt Domsch
2005-01-26 16:38                     ` Andreas Gruenbacher
2005-01-27 17:03                       ` Matt Domsch
2005-01-27 17:41                       ` Bill Davidsen
2005-01-26 14:32                 ` Paulo Marques [this message]
2005-01-27  2:10                   ` 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=41F7A9F6.20804@grupopie.com \
    --to=pmarques@grupopie.com \
    --cc=Matt_Domsch@dell.com \
    --cc=greg@kroah.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@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.