From d600419ef43dd04c0e83e4ce0fc714d2f4e5ac8c Mon Sep 17 00:00:00 2001 From: David Gstir Date: Mon, 22 Feb 2016 14:52:03 +0100 Subject: ubi: tests: Replace variable-length array with malloc() io_read and io_update of mtd-utils use variable-length arrays for test data. Since this could result in allocating many megabytes using alloca(), switch to malloc(). Signed-off-by: David Gstir Signed-off-by: David Oberhollenzer --- tests/ubi-tests/io_update.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'tests/ubi-tests/io_update.c') diff --git a/tests/ubi-tests/io_update.c b/tests/ubi-tests/io_update.c index 28b5570..2e9969e 100644 --- a/tests/ubi-tests/io_update.c +++ b/tests/ubi-tests/io_update.c @@ -76,8 +76,22 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change) leb_change ? dev_info.min_io_size * 2 : vol_info->leb_size); char vol_node[strlen(UBI_VOLUME_PATTERN) + 100]; - unsigned char buf[total_len]; + unsigned char *buf = NULL; + unsigned char *buf1 = NULL; int fd, i, j; + int ret1 = -1; + + buf = malloc(total_len); + if (!buf) { + failed("malloc"); + goto out; + } + + buf1 = malloc(total_len); + if (!buf1) { + failed("malloc"); + goto out; + } sprintf(vol_node, UBI_VOLUME_PATTERN, dev_info.dev_num, vol_info->vol_id); @@ -86,14 +100,13 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change) if (fd == -1) { failed("open"); errorm("cannot open \"%s\"\n", node); - return -1; + goto out; } for (i = 0; i < SEQ_SZ; i++) { int ret, stop = 0, len = 0; off_t off = 0; long long test_len; - unsigned char buf1[total_len]; /* * test_len is LEB size (if we test atomic LEB change) or @@ -189,12 +202,13 @@ static int test_update1(struct ubi_vol_info *vol_info, int leb_change) } } - close(fd); - return 0; - + ret1 = 0; close: close(fd); - return -1; +out: + free(buf); + free(buf1); + return ret1; } /** -- cgit v1.2.3