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