blob: a6acf556bcc75d24c8dd92f73d3a7d8fbb038b76 [file] [log] [blame]
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
Simon Glassa6c58042020-07-19 10:15:53 -06004#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -07005#include <malloc.h>
Simon Glassd66c5f72020-02-03 07:36:15 -07006#include <dm/devres.h>
Simon Glass9bc15642020-02-03 07:36:16 -07007#include "brcmnand_compat.h"
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01008
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01009static 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
29char *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}