blob: b3b3df5c042e4ec95d9e5f881b335ee1d0731722 [file] [log] [blame]
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01001// SPDX-License-Identifier: GPL-2.0+
2
Simon Glassa6c58042020-07-19 10:15:53 -06003#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -07004#include <malloc.h>
Simon Glassd66c5f72020-02-03 07:36:15 -07005#include <dm/devres.h>
Simon Glass9bc15642020-02-03 07:36:16 -07006#include "brcmnand_compat.h"
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01007
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01008static char *devm_kvasprintf(struct udevice *dev, gfp_t gfp, const char *fmt,
9 va_list ap)
10{
11 unsigned int len;
12 char *p;
13 va_list aq;
14
15 va_copy(aq, ap);
16 len = vsnprintf(NULL, 0, fmt, aq);
17 va_end(aq);
18
19 p = devm_kmalloc(dev, len + 1, gfp);
20 if (!p)
21 return NULL;
22
23 vsnprintf(p, len + 1, fmt, ap);
24
25 return p;
26}
27
28char *devm_kasprintf(struct udevice *dev, gfp_t gfp, const char *fmt, ...)
29{
30 va_list ap;
31 char *p;
32
33 va_start(ap, fmt);
34 p = devm_kvasprintf(dev, gfp, fmt, ap);
35 va_end(ap);
36
37 return p;
38}