summaryrefslogtreecommitdiff
path: root/tests/ubi-tests/rsvol.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ubi-tests/rsvol.c')
-rw-r--r--tests/ubi-tests/rsvol.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/tests/ubi-tests/rsvol.c b/tests/ubi-tests/rsvol.c
index 732bcaa..6bfade9 100644
--- a/tests/ubi-tests/rsvol.c
+++ b/tests/ubi-tests/rsvol.c
@@ -107,32 +107,39 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
long long bytes;
struct ubi_vol_info vol_info1;
char vol_node[strlen(UBI_VOLUME_PATTERN) + 100];
- unsigned char buf[vol_info->rsvd_bytes];
+ unsigned char *buf;
int fd, i, ret;
+ int ret1 = -1;
+
+ buf = malloc(vol_info->rsvd_bytes);
+ if (!buf) {
+ failed("malloc");
+ goto out;
+ }
/* Make the volume smaller and check basic volume I/O */
bytes = vol_info->rsvd_bytes - vol_info->leb_size;
if (ubi_rsvol(libubi, node, vol_info->vol_id, bytes - 1)) {
failed("ubi_rsvol");
- return -1;
+ goto out;
}
if (ubi_get_vol_info1(libubi, vol_info->dev_num, vol_info->vol_id,
&vol_info1)) {
failed("ubi_get_vol_info");
- return -1;
+ goto out;
}
if (vol_info1.rsvd_bytes != bytes) {
errorm("rsvd_bytes %lld, must be %lld",
vol_info1.rsvd_bytes, bytes);
- return -1;
+ goto out;
}
if (vol_info1.rsvd_lebs != vol_info->rsvd_lebs - 1) {
errorm("rsvd_lebs %d, must be %d",
vol_info1.rsvd_lebs, vol_info->rsvd_lebs - 1);
- return -1;
+ goto out;
}
/* Write data to the volume */
@@ -143,7 +150,7 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
if (fd == -1) {
failed("open");
errorm("cannot open \"%s\"\n", vol_node);
- return -1;
+ goto out;
}
bytes = vol_info->rsvd_bytes - vol_info->leb_size - 1;
@@ -165,20 +172,20 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
if (ubi_rsvol(libubi, node, vol_info->vol_id, bytes)) {
failed("ubi_rsvol");
- return -1;
+ goto out;
}
if (ubi_rsvol(libubi, node, vol_info->vol_id,
(long long)vol_info->leb_size * dev_info.avail_lebs)) {
failed("ubi_rsvol");
- return -1;
+ goto out;
}
fd = open(vol_node, O_RDWR);
if (fd == -1) {
failed("open");
errorm("cannot open \"%s\"\n", vol_node);
- return -1;
+ goto out;
}
/* Read data back */
@@ -200,12 +207,12 @@ static int test_rsvol1(struct ubi_vol_info *vol_info)
}
}
- close(fd);
- return 0;
-
+ ret1 = 0;
close:
close(fd);
- return -1;
+out:
+ free(buf);
+ return ret1;
}
/**