rename target/linux/generic-2.6 to generic
[15.05/openwrt.git] / target / linux / generic / patches-2.6.30 / 000-bzip_lzma_remove_nasty_hack.patch
1 From b1af4315d823a2b6659c5b14bc17f7bc61878ef4 Mon Sep 17 00:00:00 2001
2 From: Phillip Lougher <phillip@lougher.demon.co.uk>
3 Date: Thu, 6 Aug 2009 15:09:31 -0700
4 Subject: [PATCH] bzip2/lzma: remove nasty uncompressed size hack in pre-boot environment
5
6 decompress_bunzip2 and decompress_unlzma have a nasty hack that subtracts
7 4 from the input length if being called in the pre-boot environment.
8
9 This is a nasty hack because it relies on the fact that flush = NULL only
10 when called from the pre-boot environment (i.e.
11 arch/x86/boot/compressed/misc.c).  initramfs.c/do_mounts_rd.c pass in a
12 flush buffer (flush != NULL).
13
14 This hack prevents the decompressors from being used with flush = NULL by
15 other callers unless knowledge of the hack is propagated to them.
16
17 This patch removes the hack by making decompress (called only from the
18 pre-boot environment) a wrapper function that subtracts 4 from the input
19 length before calling the decompressor.
20
21 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
22 Cc: "H. Peter Anvin" <hpa@zytor.com>
23 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
24 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
25 ---
26  lib/decompress_bunzip2.c |   22 ++++++++++++++++------
27  lib/decompress_unlzma.c  |   21 ++++++++++++++++-----
28  2 files changed, 32 insertions(+), 11 deletions(-)
29
30 --- a/lib/decompress_bunzip2.c
31 +++ b/lib/decompress_bunzip2.c
32 @@ -45,9 +45,11 @@
33  */
34  
35  
36 -#ifndef STATIC
37 +#ifdef STATIC
38 +#define PREBOOT
39 +#else
40  #include <linux/decompress/bunzip2.h>
41 -#endif /* !STATIC */
42 +#endif /* STATIC */
43  
44  #include <linux/decompress/mm.h>
45  #include <linux/slab.h>
46 @@ -681,9 +683,7 @@ STATIC int INIT bunzip2(unsigned char *b
47         set_error_fn(error_fn);
48         if (flush)
49                 outbuf = malloc(BZIP2_IOBUF_SIZE);
50 -       else
51 -               len -= 4; /* Uncompressed size hack active in pre-boot
52 -                            environment */
53 +
54         if (!outbuf) {
55                 error("Could not allocate output bufer");
56                 return -1;
57 @@ -733,4 +733,14 @@ exit_0:
58         return i;
59  }
60  
61 -#define decompress bunzip2
62 +#ifdef PREBOOT
63 +STATIC int INIT decompress(unsigned char *buf, int len,
64 +                       int(*fill)(void*, unsigned int),
65 +                       int(*flush)(void*, unsigned int),
66 +                       unsigned char *outbuf,
67 +                       int *pos,
68 +                       void(*error_fn)(char *x))
69 +{
70 +       return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error_fn);
71 +}
72 +#endif
73 --- a/lib/decompress_unlzma.c
74 +++ b/lib/decompress_unlzma.c
75 @@ -29,7 +29,9 @@
76   *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
77   */
78  
79 -#ifndef STATIC
80 +#ifdef STATIC
81 +#define PREBOOT
82 +#else
83  #include <linux/decompress/unlzma.h>
84  #endif /* STATIC */
85  
86 @@ -543,9 +545,7 @@ STATIC inline int INIT unlzma(unsigned c
87         int ret = -1;
88  
89         set_error_fn(error_fn);
90 -       if (!flush)
91 -               in_len -= 4; /* Uncompressed size hack active in pre-boot
92 -                               environment */
93 +
94         if (buf)
95                 inbuf = buf;
96         else
97 @@ -645,4 +645,15 @@ exit_0:
98         return ret;
99  }
100  
101 -#define decompress unlzma
102 +#ifdef PREBOOT
103 +STATIC int INIT decompress(unsigned char *buf, int in_len,
104 +                             int(*fill)(void*, unsigned int),
105 +                             int(*flush)(void*, unsigned int),
106 +                             unsigned char *output,
107 +                             int *posp,
108 +                             void(*error_fn)(char *x)
109 +       )
110 +{
111 +       return unlzma(buf, in_len - 4, fill, flush, output, posp, error_fn);
112 +}
113 +#endif