summaryrefslogtreecommitdiff
path: root/tests/ubi-tests/io_update.c
diff options
context:
space:
mode:
authorDavid Gstir <david@sigma-star.at>2016-02-22 14:52:03 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2017-02-21 10:13:11 +0100
commitd600419ef43dd04c0e83e4ce0fc714d2f4e5ac8c (patch)
tree5de1e3cadef2bde3526b0657b78eabc6016f12d6 /tests/ubi-tests/io_update.c
parent1710e0c53e5d3768ba7a58e26ffc8cb105d2ae62 (diff)
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 <david@sigma-star.at> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/ubi-tests/io_update.c')
-rw-r--r--tests/ubi-tests/io_update.c28
1 files changed, 21 insertions, 7 deletions
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;
}
/**