diff --git a/board/samsung/smdkc100/onenand.c b/board/samsung/smdkc100/onenand.c
index 501855edd3812a63cc3d18e7879a990784be1ef3..e34cd31f24a4002cb343f187e6c62edb720598fa 100644
--- a/board/samsung/smdkc100/onenand.c
+++ b/board/samsung/smdkc100/onenand.c
@@ -22,7 +22,7 @@
  */
 
 #include <common.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 #include <linux/mtd/samsung_onenand.h>
diff --git a/common/cmd_onenand.c b/common/cmd_onenand.c
index 0f2e2087179ed46a8275b7aa92e175ccca3028d8..a0d25e55212a0c9633e89d62331f3ed223c694df 100644
--- a/common/cmd_onenand.c
+++ b/common/cmd_onenand.c
@@ -13,7 +13,7 @@
 #include <command.h>
 #include <malloc.h>
 
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 
diff --git a/common/env_onenand.c b/common/env_onenand.c
index 652665a189094bafe5eced6aaeb137da2c3c920d..7197ab6585324c930b3410f880b7641860f702a7 100644
--- a/common/env_onenand.c
+++ b/common/env_onenand.c
@@ -33,7 +33,7 @@
 #include <errno.h>
 #include <onenand_uboot.h>
 
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 
diff --git a/disk/part_dos.c b/disk/part_dos.c
index b5bcb3735c0fb6148e3c09736694b0fbb833d653..c028aaf1b15fc55f050dd5ae5d19e9c228d281e8 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -87,7 +87,7 @@ static int test_block_type(unsigned char *buffer)
 
 int test_part_dos (block_dev_desc_t *dev_desc)
 {
-	unsigned char buffer[dev_desc->blksz];
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 
 	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1) ||
 	    (buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
@@ -102,7 +102,7 @@ int test_part_dos (block_dev_desc_t *dev_desc)
 static void print_partition_extended (block_dev_desc_t *dev_desc, int ext_part_sector, int relative,
 							   int part_num)
 {
-	unsigned char buffer[dev_desc->blksz];
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 	dos_partition_t *pt;
 	int i;
 
@@ -166,7 +166,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part
 				 int relative, int part_num,
 				 int which_part, disk_partition_t *info)
 {
-	unsigned char buffer[dev_desc->blksz];
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 	dos_partition_t *pt;
 	int i;
 
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index fc2270127aeb7e4742c0974b972dca5624f5956c..e6d938417ded948b498c41590fc85435db00dfec 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -9,7 +9,7 @@
  */
 
 #include <linux/mtd/mtd.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/concat.h>
 #include <ubi_uboot.h>
 
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index a195ddab35774a9044f0446e8e0d66d880636c3a..3a81adaf60d5563d805e230515f12a3ca444439e 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -8,7 +8,7 @@
  */
 
 #include <linux/mtd/mtd.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <ubi_uboot.h>
 
 struct mtd_info *mtd_table[MAX_MTD_DEVICES];
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index f647e436681b1e1c255503152b9d6379753e6bef..96dcda2b2ba4a4bfa7226c14a9c9073dacc645fe 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -17,7 +17,7 @@
 #include <linux/list.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 
 /* Our partition linked list */
 struct list_head mtd_partitions;
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 7fd8a354791c176e1dbaa0d31105e2b43f9d29e9..e6b7a706619ca1eb1c7c7eab2d0a910413cba86d 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -29,7 +29,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/nand_ecc.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 
 #include <asm/errno.h>
 #include <asm/io.h>
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 44f7b914578d1effda938c808d8696417a6812dc..bef79bed0fe1563489a85ed9ecaa69ed25805304 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -39,7 +39,7 @@
 #include <malloc.h>
 #include <watchdog.h>
 #include <linux/err.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/nand_ecc.h>
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 2b730e09c97ade4de292c4c0bc9e3b30f026cc7a..dc6c6480e58bbed1ab272b38645347e0a9346b89 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -61,7 +61,7 @@
 
 #include <common.h>
 #include <malloc.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/nand_ecc.h>
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 1d0f196c127dd804b82375e1834a1c35d008b9c3..1a7b40eaa37fdc5909fee41e1699a077d9319a22 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -20,7 +20,7 @@
  */
 
 #include <common.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index 1354877729d9aa8a8d4814b1a414b8c02687dfb3..9d5da54708ec9ed9db9c83eff0b9939adb6d90bd 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -15,7 +15,7 @@
  */
 
 #include <common.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 #include <malloc.h>
diff --git a/drivers/mtd/onenand/onenand_uboot.c b/drivers/mtd/onenand/onenand_uboot.c
index c642016c2d2ed482a903ecf6f2ead3f119008c76..ae60c3bb71dffd2203fb8fbca5d821aa12c8a60d 100644
--- a/drivers/mtd/onenand/onenand_uboot.c
+++ b/drivers/mtd/onenand/onenand_uboot.c
@@ -14,7 +14,7 @@
  */
 
 #include <common.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 
diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c
index c9d33ec825004500b4b9056f376c03be8a279181..0d94ea5b1f3efe4d94be44845131169cc95aef02 100644
--- a/drivers/mtd/onenand/samsung.c
+++ b/drivers/mtd/onenand/samsung.c
@@ -28,7 +28,7 @@
 
 #include <common.h>
 #include <malloc.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/onenand.h>
 #include <linux/mtd/samsung_onenand.h>
diff --git a/drivers/usb/gadget/s3c_udc_otg.c b/drivers/usb/gadget/s3c_udc_otg.c
index 1050a98b6cd9601d184e7257f32249361d105c2a..9d11aea8e4c4baa40e4169aa8c1dab9ce8d5825f 100644
--- a/drivers/usb/gadget/s3c_udc_otg.c
+++ b/drivers/usb/gadget/s3c_udc_otg.c
@@ -671,7 +671,7 @@ static struct usb_request *s3c_alloc_request(struct usb_ep *ep,
 
 	debug("%s: %s %p\n", __func__, ep->name, ep);
 
-	req = kmalloc(sizeof *req, gfp_flags);
+	req = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*req));
 	if (!req)
 		return 0;
 
@@ -865,7 +865,8 @@ int s3c_udc_probe(struct s3c_plat_otg_data *pdata)
 	the_controller = dev;
 
 	for (i = 0; i < S3C_MAX_ENDPOINTS+1; i++) {
-		dev->dma_buf[i] = kmalloc(DMA_BUFFER_SIZE, GFP_KERNEL);
+		dev->dma_buf[i] = memalign(CONFIG_SYS_CACHELINE_SIZE,
+					   DMA_BUFFER_SIZE);
 		dev->dma_addr[i] = (dma_addr_t) dev->dma_buf[i];
 		invalidate_dcache_range((unsigned long) dev->dma_buf[i],
 					(unsigned long) (dev->dma_buf[i]
diff --git a/drivers/usb/gadget/s3c_udc_otg_xfer_dma.c b/drivers/usb/gadget/s3c_udc_otg_xfer_dma.c
index afd4931fa0c850d0ec53138e79e39d205c51f508..56e6e53de6fb89280872ab653240dd4d5a8ae62c 100644
--- a/drivers/usb/gadget/s3c_udc_otg_xfer_dma.c
+++ b/drivers/usb/gadget/s3c_udc_otg_xfer_dma.c
@@ -168,7 +168,7 @@ int setdma_tx(struct s3c_ep *ep, struct s3c_request *req)
 	length = req->req.length - req->req.actual;
 
 	if (ep_num == EP0_CON)
-		length = min_t(length, (u32)ep_maxpacket(ep));
+		length = min(length, (u32)ep_maxpacket(ep));
 
 	ep->len = length;
 	ep->dma_buf = buf;
diff --git a/fs/cramfs/uncompress.c b/fs/cramfs/uncompress.c
index 228fe68c11a14f7832ad3a8b7b91ae5c92fa7a75..f431cc46c1f756bb3100d5dd9830099c241cc628 100644
--- a/fs/cramfs/uncompress.c
+++ b/fs/cramfs/uncompress.c
@@ -27,9 +27,6 @@
 
 static z_stream stream;
 
-void *zalloc(void *, unsigned, unsigned);
-void zfree(void *, void *, unsigned);
-
 /* Returns length of decompressed data. */
 int cramfs_uncompress_block (void *dst, void *src, int srclen)
 {
@@ -59,8 +56,8 @@ int cramfs_uncompress_init (void)
 {
 	int err;
 
-	stream.zalloc = zalloc;
-	stream.zfree = zfree;
+	stream.zalloc = gzalloc;
+	stream.zfree = gzfree;
 	stream.next_in = 0;
 	stream.avail_in = 0;
 
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 1f95eb4cafe350cb4d69888710de77298e2535aa..a3085b51d99851b4db746368196d08ef664b0bdb 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -31,6 +31,8 @@
 #include <fat.h>
 #include <asm/byteorder.h>
 #include <part.h>
+#include <malloc.h>
+#include <linux/compiler.h>
 
 /*
  * Convert a string to lowercase.
@@ -62,7 +64,7 @@ static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
 
 int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
 {
-	unsigned char buffer[dev_desc->blksz];
+	ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
 
 	/* First close any currently found FAT filesystem */
 	cur_dev = NULL;
@@ -293,7 +295,7 @@ get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
 		return -1;
 	}
 	if (size % mydata->sect_size) {
-		__u8 tmpbuf[mydata->sect_size];
+		ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size);
 
 		idx = size / mydata->sect_size;
 		ret = disk_read(startsect + idx, 1, tmpbuf);
@@ -428,8 +430,8 @@ static int slot2str (dir_slot *slotptr, char *l_name, int *idx)
  * into 'retdent'
  * Return 0 on success, -1 otherwise.
  */
-__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
-__u8 get_vfatname_block[MAX_CLUSTSIZE];
+__u8 get_vfatname_block[MAX_CLUSTSIZE]
+	__aligned(ARCH_DMA_MINALIGN);
 
 static int
 get_vfatname (fsdata *mydata, int curclust, __u8 *cluster,
@@ -533,8 +535,8 @@ static __u8 mkcksum (const char *str)
  * Get the directory entry associated with 'filename' from the directory
  * starting at 'startsect'
  */
-__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
-__u8 get_dentfromdir_block[MAX_CLUSTSIZE];
+__u8 get_dentfromdir_block[MAX_CLUSTSIZE]
+	__aligned(ARCH_DMA_MINALIGN);
 
 static dir_entry *get_dentfromdir (fsdata *mydata, int startsect,
 				   char *filename, dir_entry *retdent,
@@ -709,7 +711,7 @@ read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
 		return -1;
 	}
 
-	block = malloc(cur_dev->blksz);
+	block = memalign(ARCH_DMA_MINALIGN, cur_dev->blksz);
 	if (block == NULL) {
 		debug("Error: allocating block\n");
 		return -1;
@@ -765,8 +767,8 @@ exit:
 	return ret;
 }
 
-__attribute__ ((__aligned__ (__alignof__ (dir_entry))))
-__u8 do_fat_read_block[MAX_CLUSTSIZE];
+__u8 do_fat_read_block[MAX_CLUSTSIZE]
+	__aligned(ARCH_DMA_MINALIGN);
 
 long
 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
@@ -828,7 +830,7 @@ do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
 	}
 
 	mydata->fatbufnum = -1;
-	mydata->fatbuf = malloc(FATBUFSIZE);
+	mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE);
 	if (mydata->fatbuf == NULL) {
 		debug("Error: allocating memory\n");
 		return -1;
diff --git a/fs/jffs2/jffs2_1pass.c b/fs/jffs2/jffs2_1pass.c
index a0b02e4dda1a0816ba8e5d6e68158ae83d1e8608..c856983ef444bfb3292a5aa2efafdd18b489e3e5 100644
--- a/fs/jffs2/jffs2_1pass.c
+++ b/fs/jffs2/jffs2_1pass.c
@@ -119,7 +119,7 @@
 #include <watchdog.h>
 #include <jffs2/jffs2.h>
 #include <jffs2/jffs2_1pass.h>
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <asm/errno.h>
 
 #include "jffs2_private.h"
diff --git a/include/linux/mtd/compat.h b/include/linux/compat.h
similarity index 92%
rename from include/linux/mtd/compat.h
rename to include/linux/compat.h
index 39c693f7a8c0a50ab1addfe1b90696908dd373e1..593b07f4b5db621b79371b8338e59579ba521314 100644
--- a/include/linux/mtd/compat.h
+++ b/include/linux/compat.h
@@ -48,5 +48,8 @@
 #define BUG_ON(condition) do { if (condition) BUG(); } while(0)
 #endif /* BUG */
 
+#define WARN_ON(x) if (x) {printf("WARNING in %s line %d\n" \
+				  , __FILE__, __LINE__); }
+
 #define PAGE_SIZE	4096
 #endif
diff --git a/include/linux/err.h b/include/linux/err.h
index 4e08c4fe685bf65cc3e381e8b805a9f8e2812a0f..96c0c72baa6b4364a552a7521e9a3fe7620f171b 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -5,7 +5,7 @@
 #if 0
 #include <linux/compiler.h>
 #else
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #endif
 
 #include <asm/errno.h>
diff --git a/include/linux/mtd/mtd-abi.h b/include/linux/mtd/mtd-abi.h
index 8d5f60c75ea093ccc48060ac18a428c525b77e76..5991157065a7a81649f8afe99993704ff1987f95 100644
--- a/include/linux/mtd/mtd-abi.h
+++ b/include/linux/mtd/mtd-abi.h
@@ -8,7 +8,7 @@
 #define __MTD_ABI_H__
 
 #if 1
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #endif
 
 struct erase_info_user {
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index da6fa184c3397d4dce226525e30f06f501da2f29..82704de0835561907e5d77467c7c27458890f2e4 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -20,7 +20,7 @@
 
 #include "config.h"
 
-#include "linux/mtd/compat.h"
+#include "linux/compat.h"
 #include "linux/mtd/mtd.h"
 #include "linux/mtd/bbm.h"
 
diff --git a/include/linux/mtd/onenand.h b/include/linux/mtd/onenand.h
index bb4a4a6b28ee28a31bbbd379381bb94de44db615..e7b63ddd107243d93d2955e4c0b2656957b8f9ae 100644
--- a/include/linux/mtd/onenand.h
+++ b/include/linux/mtd/onenand.h
@@ -17,7 +17,7 @@
 /* Note: The header order is impoertant */
 #include <onenand_uboot.h>
 
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/bbm.h>
 
 #define MAX_DIES		2
diff --git a/include/nand.h b/include/nand.h
index 8b3a1a77a399552b9eb8e10cc9a2746e24989711..a48b1b8ed1a514831511303abca62cb48fccb96d 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -37,7 +37,7 @@
 
 extern void nand_init(void);
 
-#include <linux/mtd/compat.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 
diff --git a/include/u-boot/zlib.h b/include/u-boot/zlib.h
index fb2708186dcf7b0adb79b0c9eea89edcec50b201..fbb08a32879e68b102cb9d1bdff1ca5aaf488ed3 100644
--- a/include/u-boot/zlib.h
+++ b/include/u-boot/zlib.h
@@ -691,6 +691,9 @@ ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int  windowBits,
 	struct internal_state {int dummy;}; /* hack for buggy compilers */
 #endif
 
+extern void *gzalloc(void *, unsigned, unsigned);
+extern void gzfree(void *, void *, unsigned);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/usb/lin_gadget_compat.h b/include/usb/lin_gadget_compat.h
index fce3be7e80291a57709682118d6f3d2cc7c0c23b..8287b9de9f97d8a05308ba31ffe4562ae1ead76b 100644
--- a/include/usb/lin_gadget_compat.h
+++ b/include/usb/lin_gadget_compat.h
@@ -23,6 +23,8 @@
 #ifndef __LIN_COMPAT_H__
 #define __LIN_COMPAT_H__
 
+#include <linux/compat.h>
+
 /* common */
 #define spin_lock_init(...)
 #define spin_lock(...)
@@ -36,26 +38,12 @@
 #define mutex_lock(...)
 #define mutex_unlock(...)
 
-#define WARN_ON(x) if (x) {printf("WARNING in %s line %d\n" \
-				  , __FILE__, __LINE__); }
-
-#define KERN_WARNING
-#define KERN_ERR
-#define KERN_NOTICE
-#define KERN_DEBUG
-
 #define GFP_KERNEL	0
 
 #define IRQ_HANDLED	1
 
 #define ENOTSUPP	524	/* Operation is not supported */
 
-#define kmalloc(size, type) memalign(CONFIG_SYS_CACHELINE_SIZE, size)
-#define kfree(addr) free(addr)
-#define mdelay(n) ({unsigned long msec = (n); while (msec--) udelay(1000); })
-
-#define __iomem
-#define min_t min
 #define dma_cache_maint(addr, size, mode) cache_flush()
 void cache_flush(void);
 
diff --git a/lib/gunzip.c b/lib/gunzip.c
index 8b16b2495fbec50956ff027c5e49803435034592..99a8ab028760bbd2d5ae44e5e4eed03b2f99106a 100644
--- a/lib/gunzip.c
+++ b/lib/gunzip.c
@@ -36,10 +36,7 @@
 #define RESERVED		0xe0
 #define DEFLATED		8
 
-void *zalloc(void *, unsigned, unsigned);
-void zfree(void *, void *, unsigned);
-
-void *zalloc(void *x, unsigned items, unsigned size)
+void *gzalloc(void *x, unsigned items, unsigned size)
 {
 	void *p;
 
@@ -51,7 +48,7 @@ void *zalloc(void *x, unsigned items, unsigned size)
 	return (p);
 }
 
-void zfree(void *x, void *addr, unsigned nb)
+void gzfree(void *x, void *addr, unsigned nb)
 {
 	free (addr);
 }
@@ -94,8 +91,8 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
 	z_stream s;
 	int r;
 
-	s.zalloc = zalloc;
-	s.zfree = zfree;
+	s.zalloc = gzalloc;
+	s.zfree = gzfree;
 
 	r = inflateInit2(&s, -MAX_WBITS);
 	if (r != Z_OK) {