ia64/xen-unstable
changeset 12593:c242b6d6a64a
[LINUX] Import kasprintf patch from upstream.
kasprintf has been merged upstream with a slightly different protoype
to the one in Xen. Import this patch and fixup the Xen tree to fit.
Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
kasprintf has been merged upstream with a slightly different protoype
to the one in Xen. Import this patch and fixup the Xen tree to fit.
Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
line diff
1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c Mon Nov 27 13:50:02 2006 +0000 1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c Mon Nov 27 13:50:02 2006 +0000 1.3 @@ -39,9 +39,6 @@ 1.4 #include <xen/platform-compat.h> 1.5 #endif 1.6 1.7 -/* xenbus_probe.c */ 1.8 -extern char *kasprintf(const char *fmt, ...); 1.9 - 1.10 #define DPRINTK(fmt, args...) \ 1.11 pr_debug("xenbus_client (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, ##args) 1.12 1.13 @@ -88,7 +85,7 @@ int xenbus_watch_path2(struct xenbus_dev 1.14 const char **, unsigned int)) 1.15 { 1.16 int err; 1.17 - char *state = kasprintf("%s/%s", path, path2); 1.18 + char *state = kasprintf(GFP_KERNEL, "%s/%s", path, path2); 1.19 if (!state) { 1.20 xenbus_dev_fatal(dev, -ENOMEM, "allocating path for watch"); 1.21 return -ENOMEM; 1.22 @@ -156,7 +153,7 @@ EXPORT_SYMBOL_GPL(xenbus_frontend_closed 1.23 */ 1.24 static char *error_path(struct xenbus_device *dev) 1.25 { 1.26 - return kasprintf("error/%s", dev->nodename); 1.27 + return kasprintf(GFP_KERNEL, "error/%s", dev->nodename); 1.28 } 1.29 1.30
2.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Mon Nov 27 13:50:02 2006 +0000 2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Mon Nov 27 13:50:02 2006 +0000 2.3 @@ -444,27 +444,6 @@ static void xenbus_dev_release(struct de 2.4 kfree(to_xenbus_device(dev)); 2.5 } 2.6 2.7 -/* Simplified asprintf. */ 2.8 -char *kasprintf(const char *fmt, ...) 2.9 -{ 2.10 - va_list ap; 2.11 - unsigned int len; 2.12 - char *p, dummy[1]; 2.13 - 2.14 - va_start(ap, fmt); 2.15 - /* FIXME: vsnprintf has a bug, NULL should work */ 2.16 - len = vsnprintf(dummy, 0, fmt, ap); 2.17 - va_end(ap); 2.18 - 2.19 - p = kmalloc(len + 1, GFP_KERNEL); 2.20 - if (!p) 2.21 - return NULL; 2.22 - va_start(ap, fmt); 2.23 - vsprintf(p, fmt, ap); 2.24 - va_end(ap); 2.25 - return p; 2.26 -} 2.27 - 2.28 static ssize_t xendev_show_nodename(struct device *dev, 2.29 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13) 2.30 struct device_attribute *attr, 2.31 @@ -547,7 +526,7 @@ static int xenbus_probe_frontend(const c 2.32 char *nodename; 2.33 int err; 2.34 2.35 - nodename = kasprintf("%s/%s/%s", xenbus_frontend.root, type, name); 2.36 + nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", xenbus_frontend.root, type, name); 2.37 if (!nodename) 2.38 return -ENOMEM; 2.39 2.40 @@ -644,7 +623,7 @@ void dev_changed(const char *node, struc 2.41 rootlen = strsep_len(node, '/', bus->levels); 2.42 if (rootlen < 0) 2.43 return; 2.44 - root = kasprintf("%.*s", rootlen, node); 2.45 + root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node); 2.46 if (!root) 2.47 return; 2.48
3.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.h Mon Nov 27 13:50:02 2006 +0000 3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.h Mon Nov 27 13:50:02 2006 +0000 3.3 @@ -70,8 +70,5 @@ extern int xenbus_probe_devices(struct x 3.4 3.5 extern void dev_changed(const char *node, struct xen_bus_type *bus); 3.6 3.7 -/* Simplified asprintf. Probably belongs in lib */ 3.8 -extern char *kasprintf(const char *fmt, ...); 3.9 - 3.10 #endif 3.11
4.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe_backend.c Mon Nov 27 13:50:02 2006 +0000 4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe_backend.c Mon Nov 27 13:50:02 2006 +0000 4.3 @@ -188,7 +188,7 @@ static int xenbus_probe_backend_unit(con 4.4 char *nodename; 4.5 int err; 4.6 4.7 - nodename = kasprintf("%s/%s", dir, name); 4.8 + nodename = kasprintf(GFP_KERNEL, "%s/%s", dir, name); 4.9 if (!nodename) 4.10 return -ENOMEM; 4.11 4.12 @@ -209,7 +209,7 @@ static int xenbus_probe_backend(const ch 4.13 4.14 DPRINTK(""); 4.15 4.16 - nodename = kasprintf("%s/%s/%s", xenbus_backend.root, type, domid); 4.17 + nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", xenbus_backend.root, type, domid); 4.18 if (!nodename) 4.19 return -ENOMEM; 4.20
5.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c Mon Nov 27 13:50:02 2006 +0000 5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c Mon Nov 27 13:50:02 2006 +0000 5.3 @@ -51,9 +51,6 @@ 5.4 #include <xen/platform-compat.h> 5.5 #endif 5.6 5.7 -/* xenbus_probe.c */ 5.8 -extern char *kasprintf(const char *fmt, ...); 5.9 - 5.10 struct xs_stored_msg { 5.11 struct list_head list; 5.12 5.13 @@ -295,9 +292,9 @@ static char *join(const char *dir, const 5.14 char *buffer; 5.15 5.16 if (strlen(name) == 0) 5.17 - buffer = kasprintf("%s", dir); 5.18 + buffer = kasprintf(GFP_KERNEL, "%s", dir); 5.19 else 5.20 - buffer = kasprintf("%s/%s", dir, name); 5.21 + buffer = kasprintf(GFP_KERNEL, "%s/%s", dir, name); 5.22 return (!buffer) ? ERR_PTR(-ENOMEM) : buffer; 5.23 } 5.24
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/patches/linux-2.6.16.32/kasprintf.patch Mon Nov 27 13:50:02 2006 +0000 6.3 @@ -0,0 +1,59 @@ 6.4 +commit e905914f96e11862b130dd229f73045dad9a34e8 6.5 +Author: Jeremy Fitzhardinge <jeremy@xensource.com> 6.6 +Date: Sun Jun 25 05:49:17 2006 -0700 6.7 + 6.8 + [PATCH] Implement kasprintf 6.9 + 6.10 + Implement kasprintf, a kernel version of asprintf. This allocates the 6.11 + memory required for the formatted string, including the trailing '\0'. 6.12 + Returns NULL on allocation failure. 6.13 + 6.14 + Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> 6.15 + Signed-off-by: Chris Wright <chrisw@sous-sol.org> 6.16 + Signed-off-by: Andrew Morton <akpm@osdl.org> 6.17 + Signed-off-by: Linus Torvalds <torvalds@osdl.org> 6.18 + 6.19 +diff --git a/include/linux/kernel.h b/include/linux/kernel.h 6.20 +index 8c21aaa..3c5e4c2 100644 6.21 +--- a/include/linux/kernel.h 6.22 ++++ b/include/linux/kernel.h 6.23 +@@ -117,6 +117,8 @@ extern int scnprintf(char * buf, size_t 6.24 + __attribute__ ((format (printf, 3, 4))); 6.25 + extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) 6.26 + __attribute__ ((format (printf, 3, 0))); 6.27 ++extern char *kasprintf(gfp_t gfp, const char *fmt, ...) 6.28 ++ __attribute__ ((format (printf, 2, 3))); 6.29 + 6.30 + extern int sscanf(const char *, const char *, ...) 6.31 + __attribute__ ((format (scanf, 2, 3))); 6.32 +diff --git a/lib/vsprintf.c b/lib/vsprintf.c 6.33 +index f595947..797428a 100644 6.34 +--- a/lib/vsprintf.c 6.35 ++++ b/lib/vsprintf.c 6.36 +@@ -849,3 +849,26 @@ int sscanf(const char * buf, const char 6.37 + } 6.38 + 6.39 + EXPORT_SYMBOL(sscanf); 6.40 ++ 6.41 ++ 6.42 ++/* Simplified asprintf. */ 6.43 ++char *kasprintf(gfp_t gfp, const char *fmt, ...) 6.44 ++{ 6.45 ++ va_list ap; 6.46 ++ unsigned int len; 6.47 ++ char *p; 6.48 ++ 6.49 ++ va_start(ap, fmt); 6.50 ++ len = vsnprintf(NULL, 0, fmt, ap); 6.51 ++ va_end(ap); 6.52 ++ 6.53 ++ p = kmalloc(len+1, gfp); 6.54 ++ if (!p) 6.55 ++ return NULL; 6.56 ++ va_start(ap, fmt); 6.57 ++ vsnprintf(p, len+1, fmt, ap); 6.58 ++ va_end(ap); 6.59 ++ return p; 6.60 ++} 6.61 ++ 6.62 ++EXPORT_SYMBOL(kasprintf);
7.1 --- a/patches/linux-2.6.16.32/series Mon Nov 27 13:50:02 2006 +0000 7.2 +++ b/patches/linux-2.6.16.32/series Mon Nov 27 13:50:02 2006 +0000 7.3 @@ -23,3 +23,5 @@ xenoprof-generic.patch 7.4 x86-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch 7.5 x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch 7.6 x86-elfnote-as-preprocessor-macro.patch 7.7 +vsnprintf.patch 7.8 +kasprintf.patch
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/patches/linux-2.6.16.32/vsnprintf.patch Mon Nov 27 13:50:02 2006 +0000 8.3 @@ -0,0 +1,211 @@ 8.4 +commit f796937a062c7aeb44cd0e75e1586c8543634a7d 8.5 +Author: Jeremy Fitzhardinge <jeremy@xensource.com> 8.6 +Date: Sun Jun 25 05:49:17 2006 -0700 8.7 + 8.8 + [PATCH] Fix bounds check in vsnprintf, to allow for a 0 size and NULL buffer 8.9 + 8.10 + This change allows callers to use a 0-byte buffer and a NULL buffer pointer 8.11 + with vsnprintf, so it can be used to determine how large the resulting 8.12 + formatted string will be. 8.13 + 8.14 + Previously the code effectively treated a size of 0 as a size of 4G (on 8.15 + 32-bit systems), with other checks preventing it from actually trying to 8.16 + emit the string - but the terminal \0 would still be written, which would 8.17 + crash if the buffer is NULL. 8.18 + 8.19 + This change changes the boundary check so that 'end' points to the putative 8.20 + location of the terminal '\0', which is only written if size > 0. 8.21 + 8.22 + vsnprintf still allows the buffer size to be set very large, to allow 8.23 + unbounded buffer sizes (to implement sprintf, etc). 8.24 + 8.25 + [akpm@osdl.org: fix long-vs-longlong confusion] 8.26 + Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com> 8.27 + Signed-off-by: Chris Wright <chrisw@sous-sol.org> 8.28 + Signed-off-by: Andrew Morton <akpm@osdl.org> 8.29 + Signed-off-by: Linus Torvalds <torvalds@osdl.org> 8.30 + 8.31 +diff --git a/lib/vsprintf.c b/lib/vsprintf.c 8.32 +index b07db5c..f595947 100644 8.33 +--- a/lib/vsprintf.c 8.34 ++++ b/lib/vsprintf.c 8.35 +@@ -187,49 +187,49 @@ static char * number(char * buf, char * 8.36 + size -= precision; 8.37 + if (!(type&(ZEROPAD+LEFT))) { 8.38 + while(size-->0) { 8.39 +- if (buf <= end) 8.40 ++ if (buf < end) 8.41 + *buf = ' '; 8.42 + ++buf; 8.43 + } 8.44 + } 8.45 + if (sign) { 8.46 +- if (buf <= end) 8.47 ++ if (buf < end) 8.48 + *buf = sign; 8.49 + ++buf; 8.50 + } 8.51 + if (type & SPECIAL) { 8.52 + if (base==8) { 8.53 +- if (buf <= end) 8.54 ++ if (buf < end) 8.55 + *buf = '0'; 8.56 + ++buf; 8.57 + } else if (base==16) { 8.58 +- if (buf <= end) 8.59 ++ if (buf < end) 8.60 + *buf = '0'; 8.61 + ++buf; 8.62 +- if (buf <= end) 8.63 ++ if (buf < end) 8.64 + *buf = digits[33]; 8.65 + ++buf; 8.66 + } 8.67 + } 8.68 + if (!(type & LEFT)) { 8.69 + while (size-- > 0) { 8.70 +- if (buf <= end) 8.71 ++ if (buf < end) 8.72 + *buf = c; 8.73 + ++buf; 8.74 + } 8.75 + } 8.76 + while (i < precision--) { 8.77 +- if (buf <= end) 8.78 ++ if (buf < end) 8.79 + *buf = '0'; 8.80 + ++buf; 8.81 + } 8.82 + while (i-- > 0) { 8.83 +- if (buf <= end) 8.84 ++ if (buf < end) 8.85 + *buf = tmp[i]; 8.86 + ++buf; 8.87 + } 8.88 + while (size-- > 0) { 8.89 +- if (buf <= end) 8.90 ++ if (buf < end) 8.91 + *buf = ' '; 8.92 + ++buf; 8.93 + } 8.94 +@@ -272,7 +272,8 @@ int vsnprintf(char *buf, size_t size, co 8.95 + /* 'z' changed to 'Z' --davidm 1/25/99 */ 8.96 + /* 't' added for ptrdiff_t */ 8.97 + 8.98 +- /* Reject out-of-range values early */ 8.99 ++ /* Reject out-of-range values early. Large positive sizes are 8.100 ++ used for unknown buffer sizes. */ 8.101 + if (unlikely((int) size < 0)) { 8.102 + /* There can be only one.. */ 8.103 + static int warn = 1; 8.104 +@@ -282,16 +283,17 @@ int vsnprintf(char *buf, size_t size, co 8.105 + } 8.106 + 8.107 + str = buf; 8.108 +- end = buf + size - 1; 8.109 ++ end = buf + size; 8.110 + 8.111 +- if (end < buf - 1) { 8.112 +- end = ((void *) -1); 8.113 +- size = end - buf + 1; 8.114 ++ /* Make sure end is always >= buf */ 8.115 ++ if (end < buf) { 8.116 ++ end = ((void *)-1); 8.117 ++ size = end - buf; 8.118 + } 8.119 + 8.120 + for (; *fmt ; ++fmt) { 8.121 + if (*fmt != '%') { 8.122 +- if (str <= end) 8.123 ++ if (str < end) 8.124 + *str = *fmt; 8.125 + ++str; 8.126 + continue; 8.127 +@@ -357,17 +359,17 @@ int vsnprintf(char *buf, size_t size, co 8.128 + case 'c': 8.129 + if (!(flags & LEFT)) { 8.130 + while (--field_width > 0) { 8.131 +- if (str <= end) 8.132 ++ if (str < end) 8.133 + *str = ' '; 8.134 + ++str; 8.135 + } 8.136 + } 8.137 + c = (unsigned char) va_arg(args, int); 8.138 +- if (str <= end) 8.139 ++ if (str < end) 8.140 + *str = c; 8.141 + ++str; 8.142 + while (--field_width > 0) { 8.143 +- if (str <= end) 8.144 ++ if (str < end) 8.145 + *str = ' '; 8.146 + ++str; 8.147 + } 8.148 +@@ -382,18 +384,18 @@ int vsnprintf(char *buf, size_t size, co 8.149 + 8.150 + if (!(flags & LEFT)) { 8.151 + while (len < field_width--) { 8.152 +- if (str <= end) 8.153 ++ if (str < end) 8.154 + *str = ' '; 8.155 + ++str; 8.156 + } 8.157 + } 8.158 + for (i = 0; i < len; ++i) { 8.159 +- if (str <= end) 8.160 ++ if (str < end) 8.161 + *str = *s; 8.162 + ++str; ++s; 8.163 + } 8.164 + while (len < field_width--) { 8.165 +- if (str <= end) 8.166 ++ if (str < end) 8.167 + *str = ' '; 8.168 + ++str; 8.169 + } 8.170 +@@ -426,7 +428,7 @@ int vsnprintf(char *buf, size_t size, co 8.171 + continue; 8.172 + 8.173 + case '%': 8.174 +- if (str <= end) 8.175 ++ if (str < end) 8.176 + *str = '%'; 8.177 + ++str; 8.178 + continue; 8.179 +@@ -449,11 +451,11 @@ int vsnprintf(char *buf, size_t size, co 8.180 + break; 8.181 + 8.182 + default: 8.183 +- if (str <= end) 8.184 ++ if (str < end) 8.185 + *str = '%'; 8.186 + ++str; 8.187 + if (*fmt) { 8.188 +- if (str <= end) 8.189 ++ if (str < end) 8.190 + *str = *fmt; 8.191 + ++str; 8.192 + } else { 8.193 +@@ -483,14 +485,13 @@ int vsnprintf(char *buf, size_t size, co 8.194 + str = number(str, end, num, base, 8.195 + field_width, precision, flags); 8.196 + } 8.197 +- if (str <= end) 8.198 +- *str = '\0'; 8.199 +- else if (size > 0) 8.200 +- /* don't write out a null byte if the buf size is zero */ 8.201 +- *end = '\0'; 8.202 +- /* the trailing null byte doesn't count towards the total 8.203 +- * ++str; 8.204 +- */ 8.205 ++ if (size > 0) { 8.206 ++ if (str < end) 8.207 ++ *str = '\0'; 8.208 ++ else 8.209 ++ *end = '\0'; 8.210 ++ } 8.211 ++ /* the trailing null byte doesn't count towards the total */ 8.212 + return str-buf; 8.213 + } 8.214 +
9.1 --- a/unmodified_drivers/linux-2.6/compat-include/xen/platform-compat.h Mon Nov 27 13:50:02 2006 +0000 9.2 +++ b/unmodified_drivers/linux-2.6/compat-include/xen/platform-compat.h Mon Nov 27 13:50:02 2006 +0000 9.3 @@ -64,4 +64,9 @@ void *kzalloc(size_t size, int flags); 9.4 #define end_that_request_last(req, uptodate) end_that_request_last(req) 9.5 #endif 9.6 9.7 +#if defined(_LINUX_KERNEL_H) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 9.8 +extern char *kasprintf(gfp_t gfp, const char *fmt, ...) 9.9 + __attribute__ ((format (printf, 2, 3))); 9.10 #endif 9.11 + 9.12 +#endif
10.1 --- a/unmodified_drivers/linux-2.6/platform-pci/platform-compat.c Mon Nov 27 13:50:02 2006 +0000 10.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-compat.c Mon Nov 27 13:50:02 2006 +0000 10.3 @@ -114,3 +114,26 @@ void *kzalloc(size_t size, int flags) 10.4 } 10.5 EXPORT_SYMBOL(kzalloc); 10.6 #endif 10.7 + 10.8 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) 10.9 +/* Simplified asprintf. */ 10.10 +char *kasprintf(gfp_t gfp, const char *fmt, ...) 10.11 +{ 10.12 + va_list ap; 10.13 + unsigned int len; 10.14 + char *p, dummy[1]; 10.15 + 10.16 + va_start(ap, fmt); 10.17 + len = vsnprintf(dummy, 0, fmt, ap); 10.18 + va_end(ap); 10.19 + 10.20 + p = kmalloc(len + 1, gfp); 10.21 + if (!p) 10.22 + return NULL; 10.23 + va_start(ap, fmt); 10.24 + vsprintf(p, fmt, ap); 10.25 + va_end(ap); 10.26 + return p; 10.27 +} 10.28 +EXPORT_SYMBOL(kasprintf); 10.29 +#endif