aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/of/unittest.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 070caefb3b39..df93149d6146 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -254,12 +254,18 @@ static void __init of_unittest_check_tree_linkage(void)
254static void __init of_unittest_printf_one(struct device_node *np, const char *fmt, 254static void __init of_unittest_printf_one(struct device_node *np, const char *fmt,
255 const char *expected) 255 const char *expected)
256{ 256{
257 unsigned char buf[strlen(expected)+10]; 257 unsigned char *buf;
258 int buf_size;
258 int size, i; 259 int size, i;
259 260
261 buf_size = strlen(expected) + 10;
262 buf = kmalloc(buf_size, GFP_KERNEL);
263 if (!buf)
264 return;
265
260 /* Baseline; check conversion with a large size limit */ 266 /* Baseline; check conversion with a large size limit */
261 memset(buf, 0xff, sizeof(buf)); 267 memset(buf, 0xff, buf_size);
262 size = snprintf(buf, sizeof(buf) - 2, fmt, np); 268 size = snprintf(buf, buf_size - 2, fmt, np);
263 269
264 /* use strcmp() instead of strncmp() here to be absolutely sure strings match */ 270 /* use strcmp() instead of strncmp() here to be absolutely sure strings match */
265 unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff), 271 unittest((strcmp(buf, expected) == 0) && (buf[size+1] == 0xff),
@@ -270,12 +276,13 @@ static void __init of_unittest_printf_one(struct device_node *np, const char *fm
270 size++; 276 size++;
271 for (i = 0; i < 2; i++, size--) { 277 for (i = 0; i < 2; i++, size--) {
272 /* Clear the buffer, and make sure it works correctly still */ 278 /* Clear the buffer, and make sure it works correctly still */
273 memset(buf, 0xff, sizeof(buf)); 279 memset(buf, 0xff, buf_size);
274 snprintf(buf, size+1, fmt, np); 280 snprintf(buf, size+1, fmt, np);
275 unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff), 281 unittest(strncmp(buf, expected, size) == 0 && (buf[size+1] == 0xff),
276 "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n", 282 "snprintf failed; size=%i fmt='%s' expected='%s' rslt='%s'\n",
277 size, fmt, expected, buf); 283 size, fmt, expected, buf);
278 } 284 }
285 kfree(buf);
279} 286}
280 287
281static void __init of_unittest_printf(void) 288static void __init of_unittest_printf(void)