Messages in this thread | | | Subject | Re: [PATCH V3 1/2] devres: introduce API "devm_kstrdup" | From | Joe Perches <> | Date | Tue, 28 Jan 2014 20:18:44 -0800 |
| |
On Wed, 2014-01-29 at 09:33 +0530, Manish Badarkhe wrote: > This patch introduces "devm_kstrdup" API so that the > device's driver can allocate memory and copy string. [] > diff --git a/drivers/base/devres.c b/drivers/base/devres.c [] > @@ -791,6 +791,32 @@ void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) > EXPORT_SYMBOL_GPL(devm_kmalloc); > > /** > + * devm_kstrdup - Allocate resource managed space and > + * and copy an existing string > + * @dev: Device to allocate memory for > + * @s: the string to duplicate > + * @size: Allocation size
Why is size necessary at all? I think it should be calculated by strlen
> +char *devm_kstrdup(struct device *dev, > + const char *s, size_t size, gfp_t gfp) > +{ > + char *buf; > + > + if (!s) > + return NULL; > + > + buf = devm_kzalloc(dev, size, gfp);
If this is really necessary, please use devm_kmalloc
| |