* net-2.6.24 breaks powerpc mysteriously
@ 2007-10-12 2:22 Andrew Morton
2007-10-12 2:45 ` David Miller
2007-10-12 3:52 ` Paul Mackerras
0 siblings, 2 replies; 11+ messages in thread
From: Andrew Morton @ 2007-10-12 2:22 UTC (permalink / raw)
To: netdev, Sam Ravnborg, Paul Mackerras, Benjamin Herrenschmidt,
David S. Miller
With net-2.6.24 (pulled yesterday) applied:
g5:/usr/src/25> ml arch/powerpc/boot/inflate.o
Using ARCH=powerpc CROSS_COMPILE=
CHK include/linux/version.h
CHK include/linux/utsrelease.h
CALL scripts/checksyscalls.sh
BOOTCC arch/powerpc/boot/inflate.o
arch/powerpc/boot/inflate.c:920:19: errno.h: No such file or directory
arch/powerpc/boot/inflate.c:921:18: slab.h: No such file or directory
arch/powerpc/boot/inflate.c:922:21: vmalloc.h: No such file or directory
arch/powerpc/boot/inflate.c: In function `zlib_inflate_blob':
arch/powerpc/boot/inflate.c:928: error: syntax error before '*' token
arch/powerpc/boot/inflate.c:932: error: `ENOMEM' undeclared (first use in this function)
arch/powerpc/boot/inflate.c:932: error: (Each undeclared identifier is reported only once
arch/powerpc/boot/inflate.c:932: error: for each function it appears in.)
arch/powerpc/boot/inflate.c:933: warning: implicit declaration of function `kmalloc'
arch/powerpc/boot/inflate.c:933: error: `GFP_KERNEL' undeclared (first use in this function)
arch/powerpc/boot/inflate.c:933: warning: assignment makes pointer from integer without a cast
arch/powerpc/boot/inflate.c:936: warning: assignment makes pointer from integer without a cast
arch/powerpc/boot/inflate.c:943: error: `zbuf' undeclared (first use in this function)
arch/powerpc/boot/inflate.c:955: error: `EINVAL' undeclared (first use in this function)
arch/powerpc/boot/inflate.c:960: warning: implicit declaration of function `kfree'
without it applied:
g5:/usr/src/25> ml arch/powerpc/boot/inflate.o
scripts/kconfig/conf -s arch/powerpc/Kconfig
#
# configuration written to .config
#
Using ARCH=powerpc CROSS_COMPILE=
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/modpost.o
HOSTLD scripts/mod/modpost
CHK include/linux/version.h
CHK include/linux/utsrelease.h
CC arch/powerpc/kernel/asm-offsets.s
GEN include/asm-powerpc/asm-offsets.h
CALL scripts/checksyscalls.sh
COPY arch/powerpc/boot/zlib.h
COPY arch/powerpc/boot/inflate.c
BOOTCC arch/powerpc/boot/inflate.o
.config:308:warning: trying to assign nonexistent symbol INET_LRO
.config:638:warning: trying to assign nonexistent symbol VETH
.config:639:warning: trying to assign nonexistent symbol IP1000
Note that those two COPY commands didn't happen with net-2.6.24 applied, although
that might be because `make' decided they were already performed, dunno.
I also have today's git-kbuild applied here, as well as yesterday's git-powerpc.
But I have enough to fix here so I'm going to do a report-and-run on this one.
I'll release 2.6.23-mm1 in this state for your bug-hunting convenience ;)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 2:22 net-2.6.24 breaks powerpc mysteriously Andrew Morton
@ 2007-10-12 2:45 ` David Miller
2007-10-12 4:09 ` Paul Mackerras
2007-10-14 3:40 ` Denys Vlasenko
2007-10-12 3:52 ` Paul Mackerras
1 sibling, 2 replies; 11+ messages in thread
From: David Miller @ 2007-10-12 2:45 UTC (permalink / raw)
To: akpm; +Cc: netdev, sam, paulus, benh, vda.linux
From: Andrew Morton <akpm@linux-foundation.org>
Date: Thu, 11 Oct 2007 19:22:33 -0700
> With net-2.6.24 (pulled yesterday) applied:
>
> g5:/usr/src/25> ml arch/powerpc/boot/inflate.o
> Using ARCH=powerpc CROSS_COMPILE=
> CHK include/linux/version.h
> CHK include/linux/utsrelease.h
> CALL scripts/checksyscalls.sh
> BOOTCC arch/powerpc/boot/inflate.o
> arch/powerpc/boot/inflate.c:920:19: errno.h: No such file or directory
> arch/powerpc/boot/inflate.c:921:18: slab.h: No such file or directory
> arch/powerpc/boot/inflate.c:922:21: vmalloc.h: No such file or directory
> arch/powerpc/boot/inflate.c: In function `zlib_inflate_blob':
> arch/powerpc/boot/inflate.c:928: error: syntax error before '*' token
The only thing we touched in zlib is in the patch below.
I suspect the lib/zlib_inflate/inflate.c changes, I had no idea that
some pieces of code try to use this into userspace.
I supposed a hacky fix is to add __KERNEL__ ifdef protection around
zlib_inflate_blob() and those troublesome includes. A nicer fix is
probably to change the zlib_inflate_blob() interface to pass in
pointers to alloc() and free() routines instead of calling kernel ones
directly.
Denys?
commit 8336793baf962163c9fab5a3f39614295fdbab27
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date: Sun Sep 30 17:56:49 2007 -0700
[ZLIB]: Move bnx2 driver gzip unpacker into zlib.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Acked-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 73d4a57..6d6ea56 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -2761,48 +2761,6 @@ bnx2_set_rx_mode(struct net_device *dev)
spin_unlock_bh(&bp->phy_lock);
}
-/* To be moved to generic lib/ */
-static int
-bnx2_gunzip(void *gunzip_buf, unsigned sz, u8 *zbuf, int len)
-{
- struct z_stream_s *strm;
- int rc;
-
- /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename)
- * is stripped */
-
- rc = -ENOMEM;
- strm = kmalloc(sizeof(*strm), GFP_KERNEL);
- if (strm == NULL)
- goto gunzip_nomem2;
- strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
- if (strm->workspace == NULL)
- goto gunzip_nomem3;
-
- strm->next_in = zbuf;
- strm->avail_in = len;
- strm->next_out = gunzip_buf;
- strm->avail_out = sz;
-
- rc = zlib_inflateInit2(strm, -MAX_WBITS);
- if (rc == Z_OK) {
- rc = zlib_inflate(strm, Z_FINISH);
- /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
- if (rc == Z_STREAM_END)
- rc = sz - strm->avail_out;
- else
- rc = -EINVAL;
- zlib_inflateEnd(strm);
- } else
- rc = -EINVAL;
-
- kfree(strm->workspace);
-gunzip_nomem3:
- kfree(strm);
-gunzip_nomem2:
- return rc;
-}
-
static void
load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
u32 rv2p_proc)
@@ -2858,7 +2816,7 @@ load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
text = vmalloc(FW_BUF_SIZE);
if (!text)
return -ENOMEM;
- rc = bnx2_gunzip(text, FW_BUF_SIZE, fw->gz_text, fw->gz_text_len);
+ rc = zlib_inflate_blob(text, FW_BUF_SIZE, fw->gz_text, fw->gz_text_len);
if (rc < 0) {
vfree(text);
return rc;
@@ -2935,14 +2893,14 @@ bnx2_init_cpus(struct bnx2 *bp)
text = vmalloc(FW_BUF_SIZE);
if (!text)
return -ENOMEM;
- rc = bnx2_gunzip(text, FW_BUF_SIZE, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1));
+ rc = zlib_inflate_blob(text, FW_BUF_SIZE, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1));
if (rc < 0) {
vfree(text);
goto init_cpu_err;
}
load_rv2p_fw(bp, text, rc /* == len */, RV2P_PROC1);
- rc = bnx2_gunzip(text, FW_BUF_SIZE, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2));
+ rc = zlib_inflate_blob(text, FW_BUF_SIZE, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2));
if (rc < 0) {
vfree(text);
goto init_cpu_err;
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 9e3192a..40c49cb 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -82,7 +82,7 @@
struct internal_state;
typedef struct z_stream_s {
- Byte *next_in; /* next input byte */
+ const Byte *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
@@ -699,4 +699,8 @@ extern int zlib_inflateInit2(z_streamp strm, int windowBits);
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
+/* Utility function: initialize zlib, unpack binary blob, clean up zlib,
+ * return len or negative error code. */
+extern int zlib_inflate_blob(void *dst, unsigned dst_sz, const void *src, unsigned src_sz);
+
#endif /* _ZLIB_H */
diff --git a/lib/zlib_inflate/inffast.c b/lib/zlib_inflate/inffast.c
index d84560c..8550b0c 100644
--- a/lib/zlib_inflate/inffast.c
+++ b/lib/zlib_inflate/inffast.c
@@ -69,22 +69,22 @@
void inflate_fast(z_streamp strm, unsigned start)
{
struct inflate_state *state;
- unsigned char *in; /* local strm->next_in */
- unsigned char *last; /* while in < last, enough input available */
- unsigned char *out; /* local strm->next_out */
- unsigned char *beg; /* inflate()'s initial strm->next_out */
- unsigned char *end; /* while out < end, enough space available */
+ const unsigned char *in; /* local strm->next_in */
+ const unsigned char *last; /* while in < last, enough input available */
+ unsigned char *out; /* local strm->next_out */
+ unsigned char *beg; /* inflate()'s initial strm->next_out */
+ unsigned char *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT
unsigned dmax; /* maximum distance from zlib header */
#endif
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned write; /* window write index */
- unsigned char *window; /* allocated sliding window, if wsize != 0 */
+ unsigned char *window; /* allocated sliding window, if wsize != 0 */
unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */
- code const *lcode; /* local strm->lencode */
- code const *dcode; /* local strm->distcode */
+ code const *lcode; /* local strm->lencode */
+ code const *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */
code this; /* retrieved table entry */
@@ -92,7 +92,7 @@ void inflate_fast(z_streamp strm, unsigned start)
/* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */
unsigned dist; /* match distance */
- unsigned char *from; /* where to copy match from */
+ unsigned char *from; /* where to copy match from */
/* copy state to local variables */
state = (struct inflate_state *)strm->state;
diff --git a/lib/zlib_inflate/inflate.c b/lib/zlib_inflate/inflate.c
index 7e1e311..0ad1ebf 100644
--- a/lib/zlib_inflate/inflate.c
+++ b/lib/zlib_inflate/inflate.c
@@ -332,14 +332,14 @@ static int zlib_inflateSyncPacket(z_streamp strm)
int zlib_inflate(z_streamp strm, int flush)
{
struct inflate_state *state;
- unsigned char *next; /* next input */
- unsigned char *put; /* next output */
+ const unsigned char *next; /* next input */
+ unsigned char *put; /* next output */
unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned in, out; /* save starting available input and output */
unsigned copy; /* number of stored or match bytes to copy */
- unsigned char *from; /* where to copy match bytes from */
+ unsigned char *from; /* where to copy match bytes from */
code this; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
@@ -897,7 +897,7 @@ int zlib_inflateIncomp(z_stream *z)
/* Setup some variables to allow misuse of updateWindow */
z->avail_out = 0;
- z->next_out = z->next_in + z->avail_in;
+ z->next_out = (unsigned char*)z->next_in + z->avail_in;
zlib_updatewindow(z, z->avail_in);
@@ -916,3 +916,50 @@ int zlib_inflateIncomp(z_stream *z)
return Z_OK;
}
+
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+
+/* Utility function: initialize zlib, unpack binary blob, clean up zlib,
+ * return len or negative error code. */
+int zlib_inflate_blob(void *gunzip_buf, unsigned sz, const void *buf, unsigned len)
+{
+ const u8 *zbuf = buf;
+ struct z_stream_s *strm;
+ int rc;
+
+ rc = -ENOMEM;
+ strm = kmalloc(sizeof(*strm), GFP_KERNEL);
+ if (strm == NULL)
+ goto gunzip_nomem1;
+ strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
+ if (strm->workspace == NULL)
+ goto gunzip_nomem2;
+
+ /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename)
+ * expected to be stripped from input */
+
+ strm->next_in = zbuf;
+ strm->avail_in = len;
+ strm->next_out = gunzip_buf;
+ strm->avail_out = sz;
+
+ rc = zlib_inflateInit2(strm, -MAX_WBITS);
+ if (rc == Z_OK) {
+ rc = zlib_inflate(strm, Z_FINISH);
+ /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
+ if (rc == Z_STREAM_END)
+ rc = sz - strm->avail_out;
+ else
+ rc = -EINVAL;
+ zlib_inflateEnd(strm);
+ } else
+ rc = -EINVAL;
+
+ kfree(strm->workspace);
+gunzip_nomem2:
+ kfree(strm);
+gunzip_nomem1:
+ return rc; /* returns Z_OK (0) if successful */
+}
diff --git a/lib/zlib_inflate/inflate_syms.c b/lib/zlib_inflate/inflate_syms.c
index 2061d4f..67329fe 100644
--- a/lib/zlib_inflate/inflate_syms.c
+++ b/lib/zlib_inflate/inflate_syms.c
@@ -16,4 +16,5 @@ EXPORT_SYMBOL(zlib_inflateInit2);
EXPORT_SYMBOL(zlib_inflateEnd);
EXPORT_SYMBOL(zlib_inflateReset);
EXPORT_SYMBOL(zlib_inflateIncomp);
+EXPORT_SYMBOL(zlib_inflate_blob);
MODULE_LICENSE("GPL");
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 2:22 net-2.6.24 breaks powerpc mysteriously Andrew Morton
2007-10-12 2:45 ` David Miller
@ 2007-10-12 3:52 ` Paul Mackerras
2007-10-12 4:25 ` Andrew Morton
1 sibling, 1 reply; 11+ messages in thread
From: Paul Mackerras @ 2007-10-12 3:52 UTC (permalink / raw)
To: Andrew Morton
Cc: netdev, Sam Ravnborg, Benjamin Herrenschmidt, David S. Miller
Andrew Morton writes:
> arch/powerpc/boot/inflate.c:920:19: errno.h: No such file or directory
> arch/powerpc/boot/inflate.c:921:18: slab.h: No such file or directory
> arch/powerpc/boot/inflate.c:922:21: vmalloc.h: No such file or directory
We used to have our own copies of inflate.c etc. for the zImage
wrapper code to use under arch/powerpc/boot. Then someone said "why
do we have two copies of these files?" and did a patch to make the
build process copy the files from lib/zlib_inflate over and compile
them. (We can't just use the compiled .o files from lib/zlib_inflate
because the wrapper is 32-bit whereas the kernel is often 64-bit.)
Now it seems someone has made changes to the lib/zlib_inflate versions
that are OK in the context of the kernel but not in the zImage (which
is a separate program). Avoiding this kind of breakage was the reason
why I made arch/powerpc/boot have its own copies originally.
So Andrew, what do you think is better - arch/powerpc/boot having its
own copies of the zlib_inflate stuff, or #ifdefs of some kind in
lib/zlib_inflate/*.c?
Paul.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 2:45 ` David Miller
@ 2007-10-12 4:09 ` Paul Mackerras
2007-10-14 3:43 ` Denys Vlasenko
2007-10-14 3:40 ` Denys Vlasenko
1 sibling, 1 reply; 11+ messages in thread
From: Paul Mackerras @ 2007-10-12 4:09 UTC (permalink / raw)
To: David Miller; +Cc: akpm, netdev, sam, benh, vda.linux
David Miller writes:
> The only thing we touched in zlib is in the patch below.
>
> I suspect the lib/zlib_inflate/inflate.c changes, I had no idea that
> some pieces of code try to use this into userspace.
Not userspace; the zImage wrapper uses inflate.c to gunzip the
compressed kernel image. It is a separate program to the kernel,
however, and is compiled in an environment where the headers it uses
are not the kernel headers.
> I supposed a hacky fix is to add __KERNEL__ ifdef protection around
> zlib_inflate_blob() and those troublesome includes. A nicer fix is
That would do, but I don't see why zlib_inflate_blob had to be added
to inflate.c rather than being in a new file under lib/zlib_inflate.
If nothing else, that bloats configs that currently use inflate.c (in
the kernel) but don't need zlib_inflate_blob() - which would be all
the existing uses. :)
Paul.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 3:52 ` Paul Mackerras
@ 2007-10-12 4:25 ` Andrew Morton
2007-10-12 4:54 ` David Miller
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2007-10-12 4:25 UTC (permalink / raw)
To: Paul Mackerras
Cc: netdev, Sam Ravnborg, Benjamin Herrenschmidt, David S. Miller
On Fri, 12 Oct 2007 13:52:14 +1000 Paul Mackerras <paulus@samba.org> wrote:
> So Andrew, what do you think is better - arch/powerpc/boot having its
> own copies of the zlib_inflate stuff, or #ifdefs of some kind in
> lib/zlib_inflate/*.c?
The latter - copying code is evil. Keeping the existing code dual-mode
shouldn't be too hard - it's just a matter of people knowing about it.
Perhaps such code should be in its own suitably-named directory, but
whatever.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 4:25 ` Andrew Morton
@ 2007-10-12 4:54 ` David Miller
2007-10-12 5:18 ` David Miller
0 siblings, 1 reply; 11+ messages in thread
From: David Miller @ 2007-10-12 4:54 UTC (permalink / raw)
To: akpm; +Cc: paulus, netdev, sam, benh
From: Andrew Morton <akpm@linux-foundation.org>
Date: Thu, 11 Oct 2007 21:25:39 -0700
> On Fri, 12 Oct 2007 13:52:14 +1000 Paul Mackerras <paulus@samba.org> wrote:
>
> > So Andrew, what do you think is better - arch/powerpc/boot having its
> > own copies of the zlib_inflate stuff, or #ifdefs of some kind in
> > lib/zlib_inflate/*.c?
>
>
> The latter - copying code is evil. Keeping the existing code dual-mode
> shouldn't be too hard - it's just a matter of people knowing about it.
>
> Perhaps such code should be in its own suitably-named directory, but
> whatever.
I'll work on a fix for this.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 4:54 ` David Miller
@ 2007-10-12 5:18 ` David Miller
2007-10-12 5:47 ` Paul Mackerras
0 siblings, 1 reply; 11+ messages in thread
From: David Miller @ 2007-10-12 5:18 UTC (permalink / raw)
To: akpm; +Cc: paulus, netdev, sam, benh
From: David Miller <davem@davemloft.net>
Date: Thu, 11 Oct 2007 21:54:29 -0700 (PDT)
> From: Andrew Morton <akpm@linux-foundation.org>
> Date: Thu, 11 Oct 2007 21:25:39 -0700
>
> > On Fri, 12 Oct 2007 13:52:14 +1000 Paul Mackerras <paulus@samba.org> wrote:
> >
> > > So Andrew, what do you think is better - arch/powerpc/boot having its
> > > own copies of the zlib_inflate stuff, or #ifdefs of some kind in
> > > lib/zlib_inflate/*.c?
> >
> >
> > The latter - copying code is evil. Keeping the existing code dual-mode
> > shouldn't be too hard - it's just a matter of people knowing about it.
> >
> > Perhaps such code should be in its own suitably-named directory, but
> > whatever.
>
> I'll work on a fix for this.
Here is the patch I'm putting through some paces, let me know if
it solves the powerpc problem.
Thanks!
>From 95702f93bac04b7db373e57fb606a6614c5bfcb4 Mon Sep 17 00:00:00 2001
From: David S. Miller <davem@sunset.davemloft.net>
Date: Thu, 11 Oct 2007 22:15:08 -0700
Subject: [PATCH] [ZLIB]: Fix external builds of zlib_inflate code.
Move zlib_inflate_blob() out into it's own source file,
infutil.c, so that things like the powerpc zImage builder
in arch/powerpc/boot/Makefile don't end up trying to
compile it.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
lib/zlib_inflate/Makefile | 2 +-
lib/zlib_inflate/inflate.c | 47 ------------------------------------------
lib/zlib_inflate/infutil.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 48 deletions(-)
create mode 100644 lib/zlib_inflate/infutil.c
diff --git a/lib/zlib_inflate/Makefile b/lib/zlib_inflate/Makefile
index bf06548..49f8ce5 100644
--- a/lib/zlib_inflate/Makefile
+++ b/lib/zlib_inflate/Makefile
@@ -15,5 +15,5 @@
obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate.o
-zlib_inflate-objs := inffast.o inflate.o \
+zlib_inflate-objs := inffast.o inflate.o infutil.o \
inftrees.o inflate_syms.o
diff --git a/lib/zlib_inflate/inflate.c b/lib/zlib_inflate/inflate.c
index 0ad1ebf..f5ce87b 100644
--- a/lib/zlib_inflate/inflate.c
+++ b/lib/zlib_inflate/inflate.c
@@ -916,50 +916,3 @@ int zlib_inflateIncomp(z_stream *z)
return Z_OK;
}
-
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-
-/* Utility function: initialize zlib, unpack binary blob, clean up zlib,
- * return len or negative error code. */
-int zlib_inflate_blob(void *gunzip_buf, unsigned sz, const void *buf, unsigned len)
-{
- const u8 *zbuf = buf;
- struct z_stream_s *strm;
- int rc;
-
- rc = -ENOMEM;
- strm = kmalloc(sizeof(*strm), GFP_KERNEL);
- if (strm == NULL)
- goto gunzip_nomem1;
- strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
- if (strm->workspace == NULL)
- goto gunzip_nomem2;
-
- /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename)
- * expected to be stripped from input */
-
- strm->next_in = zbuf;
- strm->avail_in = len;
- strm->next_out = gunzip_buf;
- strm->avail_out = sz;
-
- rc = zlib_inflateInit2(strm, -MAX_WBITS);
- if (rc == Z_OK) {
- rc = zlib_inflate(strm, Z_FINISH);
- /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
- if (rc == Z_STREAM_END)
- rc = sz - strm->avail_out;
- else
- rc = -EINVAL;
- zlib_inflateEnd(strm);
- } else
- rc = -EINVAL;
-
- kfree(strm->workspace);
-gunzip_nomem2:
- kfree(strm);
-gunzip_nomem1:
- return rc; /* returns Z_OK (0) if successful */
-}
diff --git a/lib/zlib_inflate/infutil.c b/lib/zlib_inflate/infutil.c
new file mode 100644
index 0000000..4824c2c
--- /dev/null
+++ b/lib/zlib_inflate/infutil.c
@@ -0,0 +1,49 @@
+#include <linux/zutil.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+
+/* Utility function: initialize zlib, unpack binary blob, clean up zlib,
+ * return len or negative error code.
+ */
+int zlib_inflate_blob(void *gunzip_buf, unsigned int sz,
+ const void *buf, unsigned int len)
+{
+ const u8 *zbuf = buf;
+ struct z_stream_s *strm;
+ int rc;
+
+ rc = -ENOMEM;
+ strm = kmalloc(sizeof(*strm), GFP_KERNEL);
+ if (strm == NULL)
+ goto gunzip_nomem1;
+ strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
+ if (strm->workspace == NULL)
+ goto gunzip_nomem2;
+
+ /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename)
+ * expected to be stripped from input
+ */
+ strm->next_in = zbuf;
+ strm->avail_in = len;
+ strm->next_out = gunzip_buf;
+ strm->avail_out = sz;
+
+ rc = zlib_inflateInit2(strm, -MAX_WBITS);
+ if (rc == Z_OK) {
+ rc = zlib_inflate(strm, Z_FINISH);
+ /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
+ if (rc == Z_STREAM_END)
+ rc = sz - strm->avail_out;
+ else
+ rc = -EINVAL;
+ zlib_inflateEnd(strm);
+ } else
+ rc = -EINVAL;
+
+ kfree(strm->workspace);
+gunzip_nomem2:
+ kfree(strm);
+gunzip_nomem1:
+ return rc; /* returns Z_OK (0) if successful */
+}
--
1.5.3.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 5:18 ` David Miller
@ 2007-10-12 5:47 ` Paul Mackerras
0 siblings, 0 replies; 11+ messages in thread
From: Paul Mackerras @ 2007-10-12 5:47 UTC (permalink / raw)
To: David Miller; +Cc: akpm, netdev, sam, benh
David Miller writes:
> Here is the patch I'm putting through some paces, let me know if
> it solves the powerpc problem.
Looks fine to me.
Acked-by: Paul Mackerras <paulus@samba.org>
Thanks!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 2:45 ` David Miller
2007-10-12 4:09 ` Paul Mackerras
@ 2007-10-14 3:40 ` Denys Vlasenko
2007-10-14 4:12 ` David Miller
1 sibling, 1 reply; 11+ messages in thread
From: Denys Vlasenko @ 2007-10-14 3:40 UTC (permalink / raw)
To: David Miller; +Cc: akpm, netdev, sam, paulus, benh
[-- Attachment #1: Type: text/plain, Size: 1761 bytes --]
On Friday 12 October 2007 03:45, David Miller wrote:
> From: Andrew Morton <akpm@linux-foundation.org>
> Date: Thu, 11 Oct 2007 19:22:33 -0700
>
> > With net-2.6.24 (pulled yesterday) applied:
> >
> > g5:/usr/src/25> ml arch/powerpc/boot/inflate.o
> > Using ARCH=powerpc CROSS_COMPILE=
> > CHK include/linux/version.h
> > CHK include/linux/utsrelease.h
> > CALL scripts/checksyscalls.sh
> > BOOTCC arch/powerpc/boot/inflate.o
> > arch/powerpc/boot/inflate.c:920:19: errno.h: No such file or directory
> > arch/powerpc/boot/inflate.c:921:18: slab.h: No such file or directory
> > arch/powerpc/boot/inflate.c:922:21: vmalloc.h: No such file or directory
> > arch/powerpc/boot/inflate.c: In function `zlib_inflate_blob':
> > arch/powerpc/boot/inflate.c:928: error: syntax error before '*' token
>
> The only thing we touched in zlib is in the patch below.
>
> I suspect the lib/zlib_inflate/inflate.c changes, I had no idea that
> some pieces of code try to use this into userspace.
>
> I supposed a hacky fix is to add __KERNEL__ ifdef protection around
> zlib_inflate_blob() and those troublesome includes. A nicer fix is
> probably to change the zlib_inflate_blob() interface to pass in
> pointers to alloc() and free() routines instead of calling kernel ones
> directly.
>
> Denys?
>
> commit 8336793baf962163c9fab5a3f39614295fdbab27
> Author: Denys Vlasenko <vda.linux@googlemail.com>
> Date: Sun Sep 30 17:56:49 2007 -0700
>
> [ZLIB]: Move bnx2 driver gzip unpacker into zlib.
>
> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
> Acked-by: Michael Chan <mchan@broadcom.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
Please find updated patch in attachment.
Compile-tested.
--
vda
[-- Attachment #2: new.diff --]
[-- Type: text/x-diff, Size: 8480 bytes --]
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -2761,48 +2761,6 @@ bnx2_set_rx_mode(struct net_device *dev)
spin_unlock_bh(&bp->phy_lock);
}
-/* To be moved to generic lib/ */
-static int
-bnx2_gunzip(void *gunzip_buf, unsigned sz, u8 *zbuf, int len)
-{
- struct z_stream_s *strm;
- int rc;
-
- /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename)
- * is stripped */
-
- rc = -ENOMEM;
- strm = kmalloc(sizeof(*strm), GFP_KERNEL);
- if (strm == NULL)
- goto gunzip_nomem2;
- strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
- if (strm->workspace == NULL)
- goto gunzip_nomem3;
-
- strm->next_in = zbuf;
- strm->avail_in = len;
- strm->next_out = gunzip_buf;
- strm->avail_out = sz;
-
- rc = zlib_inflateInit2(strm, -MAX_WBITS);
- if (rc == Z_OK) {
- rc = zlib_inflate(strm, Z_FINISH);
- /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
- if (rc == Z_STREAM_END)
- rc = sz - strm->avail_out;
- else
- rc = -EINVAL;
- zlib_inflateEnd(strm);
- } else
- rc = -EINVAL;
-
- kfree(strm->workspace);
-gunzip_nomem3:
- kfree(strm);
-gunzip_nomem2:
- return rc;
-}
-
static void
load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
u32 rv2p_proc)
@@ -2858,7 +2816,7 @@ load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
text = vmalloc(FW_BUF_SIZE);
if (!text)
return -ENOMEM;
- rc = bnx2_gunzip(text, FW_BUF_SIZE, fw->gz_text, fw->gz_text_len);
+ rc = zlib_inflate_blob(text, FW_BUF_SIZE, fw->gz_text, fw->gz_text_len);
if (rc < 0) {
vfree(text);
return rc;
@@ -2935,14 +2893,14 @@ bnx2_init_cpus(struct bnx2 *bp)
text = vmalloc(FW_BUF_SIZE);
if (!text)
return -ENOMEM;
- rc = bnx2_gunzip(text, FW_BUF_SIZE, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1));
+ rc = zlib_inflate_blob(text, FW_BUF_SIZE, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1));
if (rc < 0) {
vfree(text);
goto init_cpu_err;
}
load_rv2p_fw(bp, text, rc /* == len */, RV2P_PROC1);
- rc = bnx2_gunzip(text, FW_BUF_SIZE, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2));
+ rc = zlib_inflate_blob(text, FW_BUF_SIZE, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2));
if (rc < 0) {
vfree(text);
goto init_cpu_err;
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -82,7 +82,7 @@
struct internal_state;
typedef struct z_stream_s {
- Byte *next_in; /* next input byte */
+ const Byte *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
@@ -699,4 +699,8 @@ extern int zlib_inflateInit2(z_streamp strm, int windowBits);
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
+/* Utility function: initialize zlib, unpack binary blob, clean up zlib,
+ * return len or negative error code. */
+extern int zlib_inflate_blob(void *dst, unsigned dst_sz, const void *src, unsigned src_sz);
+
#endif /* _ZLIB_H */
--- a/lib/zlib_inflate/inffast.c
+++ b/lib/zlib_inflate/inffast.c
@@ -69,22 +69,22 @@
void inflate_fast(z_streamp strm, unsigned start)
{
struct inflate_state *state;
- unsigned char *in; /* local strm->next_in */
- unsigned char *last; /* while in < last, enough input available */
- unsigned char *out; /* local strm->next_out */
- unsigned char *beg; /* inflate()'s initial strm->next_out */
- unsigned char *end; /* while out < end, enough space available */
+ const unsigned char *in; /* local strm->next_in */
+ const unsigned char *last; /* while in < last, enough input available */
+ unsigned char *out; /* local strm->next_out */
+ unsigned char *beg; /* inflate()'s initial strm->next_out */
+ unsigned char *end; /* while out < end, enough space available */
#ifdef INFLATE_STRICT
unsigned dmax; /* maximum distance from zlib header */
#endif
unsigned wsize; /* window size or zero if not using window */
unsigned whave; /* valid bytes in the window */
unsigned write; /* window write index */
- unsigned char *window; /* allocated sliding window, if wsize != 0 */
+ unsigned char *window; /* allocated sliding window, if wsize != 0 */
unsigned long hold; /* local strm->hold */
unsigned bits; /* local strm->bits */
- code const *lcode; /* local strm->lencode */
- code const *dcode; /* local strm->distcode */
+ code const *lcode; /* local strm->lencode */
+ code const *dcode; /* local strm->distcode */
unsigned lmask; /* mask for first level of length codes */
unsigned dmask; /* mask for first level of distance codes */
code this; /* retrieved table entry */
@@ -92,7 +92,7 @@ void inflate_fast(z_streamp strm, unsigned start)
/* window position, window bytes to copy */
unsigned len; /* match length, unused bytes */
unsigned dist; /* match distance */
- unsigned char *from; /* where to copy match from */
+ unsigned char *from; /* where to copy match from */
/* copy state to local variables */
state = (struct inflate_state *)strm->state;
--- a/lib/zlib_inflate/inflate.c
+++ b/lib/zlib_inflate/inflate.c
@@ -332,14 +332,14 @@ static int zlib_inflateSyncPacket(z_streamp strm)
int zlib_inflate(z_streamp strm, int flush)
{
struct inflate_state *state;
- unsigned char *next; /* next input */
- unsigned char *put; /* next output */
+ const unsigned char *next; /* next input */
+ unsigned char *put; /* next output */
unsigned have, left; /* available input and output */
unsigned long hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned in, out; /* save starting available input and output */
unsigned copy; /* number of stored or match bytes to copy */
- unsigned char *from; /* where to copy match bytes from */
+ unsigned char *from; /* where to copy match bytes from */
code this; /* current decoding table entry */
code last; /* parent table entry */
unsigned len; /* length to copy for repeats, bits to drop */
@@ -897,7 +897,7 @@ int zlib_inflateIncomp(z_stream *z)
/* Setup some variables to allow misuse of updateWindow */
z->avail_out = 0;
- z->next_out = z->next_in + z->avail_in;
+ z->next_out = (unsigned char*)z->next_in + z->avail_in;
zlib_updatewindow(z, z->avail_in);
--- a/lib/zlib_inflate/inflate_blob.c
+++ b/lib/zlib_inflate/inflate_blob.c
@@ -0,0 +1,42 @@
+/* inflate_blob.c -- decompression utility function
+ * Copyright (C) 2007 Denys Vlasenko
+ */
+
+#include <linux/zutil.h>
+#include <linux/slab.h>
+
+/* Utility function: initialize zlib, unpack binary blob, clean up zlib,
+ * return len or negative error code. */
+int zlib_inflate_blob(void *gunzip_buf, unsigned sz, const void *buf, unsigned len)
+{
+ const u8 *zbuf = buf;
+ struct z_stream_s strm; /* it's fairly small */
+ int rc;
+
+ strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
+ if (strm.workspace == NULL)
+ return -ENOMEM;
+
+ /* gzip header (1f,8b,08... 10 bytes total + possible asciz filename)
+ * expected to be stripped from input */
+
+ strm.next_in = zbuf;
+ strm.avail_in = len;
+ strm.next_out = gunzip_buf;
+ strm.avail_out = sz;
+
+ rc = zlib_inflateInit2(&strm, -MAX_WBITS);
+ if (rc == Z_OK) {
+ rc = zlib_inflate(&strm, Z_FINISH);
+ /* after Z_FINISH, only Z_STREAM_END is "we unpacked it all" */
+ if (rc == Z_STREAM_END)
+ rc = sz - strm.avail_out;
+ else
+ rc = -EINVAL;
+ zlib_inflateEnd(&strm);
+ } else
+ rc = -EINVAL;
+
+ kfree(strm.workspace);
+ return rc;
+}
--- a/lib/zlib_inflate/Makefile
+++ b/lib/zlib_inflate/Makefile
@@ -16,4 +16,4 @@
obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate.o
zlib_inflate-objs := inffast.o inflate.o \
- inftrees.o inflate_syms.o
+ inftrees.o inflate_blob.o inflate_syms.o
--- a/lib/zlib_inflate/inflate_syms.c
+++ b/lib/zlib_inflate/inflate_syms.c
@@ -16,4 +16,5 @@ EXPORT_SYMBOL(zlib_inflateInit2);
EXPORT_SYMBOL(zlib_inflateEnd);
EXPORT_SYMBOL(zlib_inflateReset);
EXPORT_SYMBOL(zlib_inflateIncomp);
+EXPORT_SYMBOL(zlib_inflate_blob);
MODULE_LICENSE("GPL");
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-12 4:09 ` Paul Mackerras
@ 2007-10-14 3:43 ` Denys Vlasenko
0 siblings, 0 replies; 11+ messages in thread
From: Denys Vlasenko @ 2007-10-14 3:43 UTC (permalink / raw)
To: Paul Mackerras; +Cc: David Miller, akpm, netdev, sam, benh
On Friday 12 October 2007 05:09, Paul Mackerras wrote:
> > I supposed a hacky fix is to add __KERNEL__ ifdef protection around
> > zlib_inflate_blob() and those troublesome includes. A nicer fix is
>
> That would do, but I don't see why zlib_inflate_blob had to be added
> to inflate.c rather than being in a new file under lib/zlib_inflate.
Done.
> If nothing else, that bloats configs that currently use inflate.c (in
> the kernel) but don't need zlib_inflate_blob() - which would be all
> the existing uses. :)
I did it.
However, in general I prefer to have a better linker, one which
is capable of eliminate unused fuctions/data on the per-object basis,
not per .o file.
Patches to implement that are sent to Sam Ravnborg.
Hopefully they will make it to mainline.
--
vda
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: net-2.6.24 breaks powerpc mysteriously
2007-10-14 3:40 ` Denys Vlasenko
@ 2007-10-14 4:12 ` David Miller
0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2007-10-14 4:12 UTC (permalink / raw)
To: vda.linux; +Cc: akpm, netdev, sam, paulus, benh
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Sun, 14 Oct 2007 04:40:46 +0100
> Please find updated patch in attachment.
> Compile-tested.
We fixed this several days ago already.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-10-14 4:12 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-12 2:22 net-2.6.24 breaks powerpc mysteriously Andrew Morton
2007-10-12 2:45 ` David Miller
2007-10-12 4:09 ` Paul Mackerras
2007-10-14 3:43 ` Denys Vlasenko
2007-10-14 3:40 ` Denys Vlasenko
2007-10-14 4:12 ` David Miller
2007-10-12 3:52 ` Paul Mackerras
2007-10-12 4:25 ` Andrew Morton
2007-10-12 4:54 ` David Miller
2007-10-12 5:18 ` David Miller
2007-10-12 5:47 ` Paul Mackerras
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).