1 // SPDX-License-Identifier: GPL-2.0+
2
3 #include <common.h>
4 #include <dm.h>
5 #include <malloc.h>
6 #include <dm/devres.h>
7 #include "brcmnand_compat.h"
8
devm_kvasprintf(struct udevice * dev,gfp_t gfp,const char * fmt,va_list ap)9 static char *devm_kvasprintf(struct udevice *dev, gfp_t gfp, const char *fmt,
10 va_list ap)
11 {
12 unsigned int len;
13 char *p;
14 va_list aq;
15
16 va_copy(aq, ap);
17 len = vsnprintf(NULL, 0, fmt, aq);
18 va_end(aq);
19
20 p = devm_kmalloc(dev, len + 1, gfp);
21 if (!p)
22 return NULL;
23
24 vsnprintf(p, len + 1, fmt, ap);
25
26 return p;
27 }
28
devm_kasprintf(struct udevice * dev,gfp_t gfp,const char * fmt,...)29 char *devm_kasprintf(struct udevice *dev, gfp_t gfp, const char *fmt, ...)
30 {
31 va_list ap;
32 char *p;
33
34 va_start(ap, fmt);
35 p = devm_kvasprintf(dev, gfp, fmt, ap);
36 va_end(ap);
37
38 return p;
39 }
40