public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [Patch] [ubifs] Don't define large array on local stack.
@ 2009-03-30  8:22 sonic zhang
  2009-03-30 15:11 ` Artem Bityutskiy
  0 siblings, 1 reply; 2+ messages in thread
From: sonic zhang @ 2009-03-30  8:22 UTC (permalink / raw)
  To: linux-mtd

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>

Index: ubi-utils/src/libubigen.c
===================================================================
--- ubi-utils/src/libubigen.c	(revision 7935)
+++ ubi-utils/src/libubigen.c	(revision 7939)
@@ -287,7 +287,7 @@
 {
 	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,9 @@
 	vi.name_len = strlen(UBI_LAYOUT_VOLUME_NAME);
 	vi.compat = UBI_LAYOUT_VOLUME_COMPAT;
 
+	if ((outbuf = malloc(ui->peb_size)) == NULL)
+		return sys_errmsg("fail to malloc outbuf");
+
 	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 +312,32 @@
 	       ui->peb_size - ui->data_offs - ui->vtbl_size);
 
 	seek = peb1 * ui->peb_size;
-	if (lseek(fd, seek, SEEK_SET) != seek)
+	if (lseek(fd, seek, SEEK_SET) != seek) {
+		free(outbuf);
 		return sys_errmsg("cannot seek output file");
+	}
+
 	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)
+	if (ret != ui->peb_size) {
+		free(outbuf);
 		return sys_errmsg("cannot write %d bytes", ui->peb_size);
+	}
 
 	seek = peb2 * ui->peb_size;
-	if (lseek(fd, seek, SEEK_SET) != seek)
+	if (lseek(fd, seek, SEEK_SET) != seek) {
+		free(outbuf);
 		return sys_errmsg("cannot seek output file");
+	}
 	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)
+	if (ret != ui->peb_size) {
+		free(outbuf);
 		return sys_errmsg("cannot write %d bytes", ui->peb_size);
+	}
 
+	free(outbuf);
 	return 0;
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch] [ubifs] Don't define large array on local stack.
  2009-03-30  8:22 [Patch] [ubifs] Don't define large array on local stack sonic zhang
@ 2009-03-30 15:11 ` Artem Bityutskiy
  0 siblings, 0 replies; 2+ messages in thread
From: Artem Bityutskiy @ 2009-03-30 15:11 UTC (permalink / raw)
  To: sonic zhang; +Cc: linux-mtd

On Mon, 2009-03-30 at 16:22 +0800, sonic zhang wrote:
> 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>

Well, this was not a proper patch applicable by git-am. But
I amended it and applied. Also I changed the patch a little
to make it nicer.

Thank you!

-- 
Best regards,
Artem Bityutskiy (Битюцкий Артём)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-03-30 15:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-30  8:22 [Patch] [ubifs] Don't define large array on local stack sonic zhang
2009-03-30 15:11 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox