spi-topcliff-pch: Fix issue for transmitting over 4KByte
[zen-stable.git] / lib / kasprintf.c
blob9c4233b23783db47322abd1ff7235c764e0cb7f4
1 /*
2 * linux/lib/kasprintf.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
7 #include <stdarg.h>
8 #include <linux/module.h>
9 #include <linux/slab.h>
10 #include <linux/types.h>
11 #include <linux/string.h>
13 /* Simplified asprintf. */
14 char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
16 unsigned int len;
17 char *p;
18 va_list aq;
20 va_copy(aq, ap);
21 len = vsnprintf(NULL, 0, fmt, aq);
22 va_end(aq);
24 p = kmalloc(len+1, gfp);
25 if (!p)
26 return NULL;
28 vsnprintf(p, len+1, fmt, ap);
30 return p;
32 EXPORT_SYMBOL(kvasprintf);
34 char *kasprintf(gfp_t gfp, const char *fmt, ...)
36 va_list ap;
37 char *p;
39 va_start(ap, fmt);
40 p = kvasprintf(gfp, fmt, ap);
41 va_end(ap);
43 return p;
45 EXPORT_SYMBOL(kasprintf);