summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsonic zhang <sonic.adi@gmail.com>2009-03-30 16:22:48 +0800
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-03-30 18:10:20 +0300
commite4244a1bc1f7afc7ba5f630591aa90ac7ccaa75a (patch)
tree181d99583d2abdfa7a3799eb54f24fb7cbe38d65
parent481c7beb341efe172777863bbe9f5e445ea3a0c2 (diff)
libubigen: don't define large array on stack
On nommu arch, local stack size is very limited and can't be enlarged on demand. So, don't define large array on local stack. Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
-rw-r--r--ubi-utils/src/libubigen.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/ubi-utils/src/libubigen.c b/ubi-utils/src/libubigen.c
index 91bb274..fddc1d8 100644
--- a/ubi-utils/src/libubigen.c
+++ b/ubi-utils/src/libubigen.c
@@ -287,7 +287,7 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2,
{
int ret;
struct ubigen_vol_info vi;
- char outbuf[ui->peb_size];
+ char *outbuf;
struct ubi_vid_hdr *vid_hdr;
off_t seek;
@@ -302,6 +302,11 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2,
vi.name_len = strlen(UBI_LAYOUT_VOLUME_NAME);
vi.compat = UBI_LAYOUT_VOLUME_COMPAT;
+ outbuf = malloc(ui->peb_size);
+ if (!outbuf)
+ return sys_errmsg("failed to allocate %d bytes",
+ ui->peb_size);
+
memset(outbuf, 0xFF, ui->data_offs);
vid_hdr = (struct ubi_vid_hdr *)(&outbuf[ui->vid_hdr_offs]);
memcpy(outbuf + ui->data_offs, vtbl, ui->vtbl_size);
@@ -309,22 +314,36 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2,
ui->peb_size - ui->data_offs - ui->vtbl_size);
seek = peb1 * ui->peb_size;
- if (lseek(fd, seek, SEEK_SET) != seek)
- return sys_errmsg("cannot seek output file");
+ if (lseek(fd, seek, SEEK_SET) != seek) {
+ sys_errmsg("cannot seek output file");
+ goto out_free;
+ }
+
ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec1);
init_vid_hdr(ui, &vi, vid_hdr, 0, NULL, 0);
ret = write(fd, outbuf, ui->peb_size);
- if (ret != ui->peb_size)
- return sys_errmsg("cannot write %d bytes", ui->peb_size);
+ if (ret != ui->peb_size) {
+ sys_errmsg("cannot write %d bytes", ui->peb_size);
+ goto out_free;
+ }
seek = peb2 * ui->peb_size;
- if (lseek(fd, seek, SEEK_SET) != seek)
- return sys_errmsg("cannot seek output file");
+ if (lseek(fd, seek, SEEK_SET) != seek) {
+ sys_errmsg("cannot seek output file");
+ goto out_free;
+ }
ubigen_init_ec_hdr(ui, (struct ubi_ec_hdr *)outbuf, ec2);
init_vid_hdr(ui, &vi, vid_hdr, 1, NULL, 0);
ret = write(fd, outbuf, ui->peb_size);
- if (ret != ui->peb_size)
- return sys_errmsg("cannot write %d bytes", ui->peb_size);
+ if (ret != ui->peb_size) {
+ sys_errmsg("cannot write %d bytes", ui->peb_size);
+ goto out_free;
+ }
+ free(outbuf);
return 0;
+
+out_free:
+ free(outbuf);
+ return -1;
}