Skip to content

Commit bef59c5

Browse files
geertugregkh
authored andcommitted
devres: Improve devm_kasprintf()/kvasprintf() support
- Add devm_kasprintf()/kvasprintf(), introduced by commit 75f2a4e ("devres: Add devm_kasprintf and devm_kvasprintf API"), to Documentation/driver-model/devres.txt, - Improve kernel doc: the string is not an existing formatted string, but is formatted into the newly-allocated buffer, - Add a __printf() annotation to devm_kasprintf(), so the compiler will verify the format string argument types. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5427035 commit bef59c5

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎Documentation/driver-model/devres.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,14 @@ MDIO
293293
MEM
294294
devm_free_pages()
295295
devm_get_free_pages()
296+
devm_kasprintf()
296297
devm_kcalloc()
297298
devm_kfree()
298299
devm_kmalloc()
299300
devm_kmalloc_array()
300301
devm_kmemdup()
301302
devm_kstrdup()
303+
devm_kvasprintf()
302304
devm_kzalloc()
303305

304306
PCI

‎drivers/base/devres.c‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,13 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
817817
EXPORT_SYMBOL_GPL(devm_kstrdup);
818818

819819
/**
820-
* devm_kvasprintf - Allocate resource managed space
821-
* for the formatted string.
820+
* devm_kvasprintf - Allocate resource managed space and format a string
821+
* into that.
822822
* @dev: Device to allocate memory for
823823
* @gfp: the GFP mask used in the devm_kmalloc() call when
824824
* allocating memory
825-
* @fmt: the formatted string to duplicate
826-
* @ap: the list of tokens to be placed in the formatted string
825+
* @fmt: The printf()-style format string
826+
* @ap: Arguments for the format string
827827
* RETURNS:
828828
* Pointer to allocated string on success, NULL on failure.
829829
*/
@@ -849,12 +849,13 @@ char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt,
849849
EXPORT_SYMBOL(devm_kvasprintf);
850850

851851
/**
852-
* devm_kasprintf - Allocate resource managed space
853-
* and copy an existing formatted string into that
852+
* devm_kasprintf - Allocate resource managed space and format a string
853+
* into that.
854854
* @dev: Device to allocate memory for
855855
* @gfp: the GFP mask used in the devm_kmalloc() call when
856856
* allocating memory
857-
* @fmt: the string to duplicate
857+
* @fmt: The printf()-style format string
858+
* @...: Arguments for the format string
858859
* RETURNS:
859860
* Pointer to allocated string on success, NULL on failure.
860861
*/

‎include/linux/device.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ extern int devres_release_group(struct device *dev, void *id);
607607
extern void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp);
608608
extern char *devm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt,
609609
va_list ap);
610-
extern char *devm_kasprintf(struct device *dev, gfp_t gfp,
611-
const char *fmt, ...);
610+
extern __printf(3, 4)
611+
char *devm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...);
612612
static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
613613
{
614614
return devm_kmalloc(dev, size, gfp | __GFP_ZERO);

0 commit comments

Comments
 (0)