mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
devres: introduce API "devm_kstrdup"
This patch introduces "devm_kstrdup" API so that the device's driver can allocate memory and copy string. Signed-off-by: Manish Badarkhe <badarkhe.manish@gmail.com> Signed-off-by: Mark Brown <broonie@linaro.org>
This commit is contained in:
parent
38dbfb59d1
commit
e31108cad3
@ -790,6 +790,32 @@ void * devm_kmalloc(struct device *dev, size_t size, gfp_t gfp)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(devm_kmalloc);
|
EXPORT_SYMBOL_GPL(devm_kmalloc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* devm_kstrdup - Allocate resource managed space and
|
||||||
|
* copy an existing string into that.
|
||||||
|
* @dev: Device to allocate memory for
|
||||||
|
* @s: the string to duplicate
|
||||||
|
* @gfp: the GFP mask used in the devm_kmalloc() call when
|
||||||
|
* allocating memory
|
||||||
|
* RETURNS:
|
||||||
|
* Pointer to allocated string on success, NULL on failure.
|
||||||
|
*/
|
||||||
|
char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
size = strlen(s) + 1;
|
||||||
|
buf = devm_kmalloc(dev, size, gfp);
|
||||||
|
if (buf)
|
||||||
|
memcpy(buf, s, size);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(devm_kstrdup);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* devm_kfree - Resource-managed kfree
|
* devm_kfree - Resource-managed kfree
|
||||||
* @dev: Device this memory belongs to
|
* @dev: Device this memory belongs to
|
||||||
|
@ -626,6 +626,7 @@ static inline void *devm_kcalloc(struct device *dev,
|
|||||||
return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
|
return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
|
||||||
}
|
}
|
||||||
extern void devm_kfree(struct device *dev, void *p);
|
extern void devm_kfree(struct device *dev, void *p);
|
||||||
|
extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp);
|
||||||
|
|
||||||
void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
|
void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
|
||||||
void __iomem *devm_request_and_ioremap(struct device *dev,
|
void __iomem *devm_request_and_ioremap(struct device *dev,
|
||||||
|
Loading…
Reference in New Issue
Block a user