Philippe Reynes | 5aa6cfb | 2019-03-15 15:14:36 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | #include <common.h> |
Simon Glass | a6c5804 | 2020-07-19 10:15:53 -0600 | [diff] [blame^] | 4 | #include <dm.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 5 | #include <malloc.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 6 | #include <dm/devres.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 7 | #include "brcmnand_compat.h" |
Philippe Reynes | 5aa6cfb | 2019-03-15 15:14:36 +0100 | [diff] [blame] | 8 | |
Philippe Reynes | 5aa6cfb | 2019-03-15 15:14:36 +0100 | [diff] [blame] | 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 | |
| 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 | } |