]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Decrease stack usage in BtrFS.
authorVladimir Serbinenko <phcoder@gmail.com>
Sat, 16 Nov 2013 15:03:28 +0000 (16:03 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Sat, 16 Nov 2013 15:03:28 +0000 (16:03 +0100)
We have only 92K of stack and using over 4K per frame is wasteful

* grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Allocate on heap
rather than stack.

ChangeLog
grub-core/fs/btrfs.c

index 3022acf6e89d9ed81585c24c4bbd650f1d73c847..9e48e39322609aced23bdf539aa459dd33f6f477 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-11-16  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Decrease stack usage in BtrFS.
+
+       We have only 92K of stack and using over 4K per frame is wasteful
+
+       * grub-core/fs/btrfs.c (grub_btrfs_lzo_decompress): Allocate on heap
+       rather than stack.
+
 2013-11-16  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Decrease stack usage in JFS.
index 49f11cc3c1b337df399a384f09fee643abdd25b6..a608527566e88b1931f437197dd7e7adf9be938f 100644 (file)
@@ -911,7 +911,6 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
 {
   grub_uint32_t total_size, cblock_size;
   grub_size_t ret = 0;
-  unsigned char buf[GRUB_BTRFS_LZO_BLOCK_SIZE];
   char *ibuf0 = ibuf;
 
   total_size = grub_le_to_cpu32 (grub_get_unaligned32 (ibuf));
@@ -955,13 +954,21 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
       if (off > 0 || osize < GRUB_BTRFS_LZO_BLOCK_SIZE)
        {
          grub_size_t to_copy = GRUB_BTRFS_LZO_BLOCK_SIZE - off;
+         grub_uint8_t *buf;
 
          if (to_copy > osize)
            to_copy = osize;
 
+         buf = grub_malloc (GRUB_BTRFS_LZO_BLOCK_SIZE);
+         if (!buf)
+           return -1;
+
          if (lzo1x_decompress_safe ((lzo_bytep)ibuf, cblock_size, buf, &usize,
              NULL) != LZO_E_OK)
-           return -1;
+           {
+             grub_free (buf);
+             return -1;
+           }
 
          if (to_copy > usize)
            to_copy = usize;
@@ -972,6 +979,8 @@ grub_btrfs_lzo_decompress(char *ibuf, grub_size_t isize, grub_off_t off,
          obuf += to_copy;
          ibuf += cblock_size;
          off = 0;
+
+         grub_free (buf);
          continue;
        }