[...]
diff --git a/Makefile b/Makefile
index 34210af..88053ba 100644
--- a/Makefile
+++ b/Makefile
@@ -826,11 +826,18 @@ include/config/kernel.release:
include/config/auto.conf FORCE
# Listed in dependency order
PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
+# prepare4 does module specific things prior to compilation
+prepare4:
+ifneq ($(CONFIG_LZO1X),n)
+ $(Q)ln -sf $(srctree)/lib/lzo1x/lzo1x_decompress.c \
+ $(srctree)/lib/lzo1x/lzo1x_decompress_safe.c
+endif
+
diff --git a/include/linux/lzo1x.h b/include/linux/lzo1x.h
[...]
+/* Size of temp buffer (workmem) required by lzo1x_compress */
+#define LZO1X_WORKMEM_SIZE ((size_t) (16384L * sizeof(unsigned char *)))
+
+/*
+ * This required 'workmem' of size LZO1X_WORKMEM_SIZE
+ */
+int lzo1x_compress(const unsigned char *src, size_t src_len,
+ unsigned char *dst, size_t *dst_len,
+ void *workmem);
+/*^^^^^^^^^^^
+ * This decompressor expects valid compressed data.
+ *
+ * If the compressed data gets corrupted somehow (e.g. transmission
+ * via an erroneous channel, disk errors, ...) it will probably crash
+ * your application because absolutely no additional checks are done.
+ */
+int lzo1x_decompress(const unsigned char *src, size_t src_len,
+ unsigned char *dst, size_t *dst_len);
+
+
+/*
+ * The `safe' decompressor. Somewhat slower.
+ *
+ * This decompressor will catch all compressed data violations and
+ * return an error code in this case.
+ */
+int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
+ unsigned char *dst, size_t *dst_len);
+#endif
diff --git a/lib/lzo1x/Makefile b/lib/lzo1x/Makefile
[...]
+#
+# When compiling this module out of tree, do 'make prepare_lzo'
+# before compiling as usual
+#
+obj-$(CONFIG_LZO1X) += lzo1x.o
+CFLAGS_lzo1x_decompress_safe.o += -DLZO1X_DECOMPRESS_SAFE
+lzo1x-objs := lzo1x_compress.o lzo1x_decompress.o lzo1x_decompress_safe.o
+
+prepare_lzo:
+ @ln -sf lzo1x_decompress.c lzo1x_decompress_safe.c
+
diff --git a/lib/lzo1x/lzo1x_decompress.c b/lib/lzo1x/lzo1x_decompress.c
[...]
+#if defined(LZO1X_DECOMPRESS_SAFE)
+input_overrun:
+ *out_len = (size_t)(op - out);
+ return LZO_E_INPUT_OVERRUN;
+
+output_overrun:
+ *out_len = (size_t)(op - out);
+ return LZO_E_OUTPUT_OVERRUN;
+
+lookbehind_overrun:
+ *out_len = (size_t)(op - out);
+ return LZO_E_LOOKBEHIND_OVERRUN;
+#endif
+}
+
+EXPORT_SYMBOL(lzo1x_decompress);
diff --git a/lib/lzo1x/lzo1x_int.h b/lib/lzo1x/lzo1x_int.h
[...]
+/* Macros for 'safe' decompression */
+#ifdef LZO1X_DECOMPRESS_SAFE
+
+#define lzo1x_decompress lzo1x_decompress_safe
+#define TEST_IP (ip < ip_end)
+#define NEED_IP(x) \
+ if ((size_t)(ip_end - ip) < (size_t)(x)) goto input_overrun
+#define NEED_OP(x) \
+ if ((size_t)(op_end - op) < (size_t)(x)) goto output_overrun
+#define TEST_LB(m_pos) \
+ if (m_pos < out || m_pos >= op) goto lookbehind_overrun
+#define HAVE_TEST_IP
+#define HAVE_ANY_OP
+
+#else /* !LZO1X_DECOMPRESS_SAFE */
+
+#define TEST_IP 1
+#define TEST_LB(x) ((void) 0)
+#define NEED_IP(x) ((void) 0)
+#define NEED_OP(x) ((void) 0)
+#undef HAVE_TEST_IP
+#undef HAVE_ANY_OP
+
+#endif /* LZO1X_DECOMPRESS_SAFE */