linux/kernel.h: sync min, max, min3, max3 macros with Linux

U-Boot has never cared about the type when we get max/min of two
values, but Linux Kernel does.  This commit gets min, max, min3, max3
macros synced with the kernel introducing type checks.

Many of references of those macros must be fixed to suppress warnings.
We have two options:
 - Use min, max, min3, max3 only when the arguments have the same type
   (or add casts to the arguments)
 - Use min_t/max_t instead with the appropriate type for the first
   argument

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Pavel Machek <pavel@denx.de>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
[trini: Fixup arch/blackfin/lib/string.c]
Signed-off-by: Tom Rini <trini@ti.com>
diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index 42a5296..58b61c2 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -210,9 +210,9 @@
 	 */
 	bootline = getenv("bootargs");
 	if (bootline) {
-		memcpy((void *) bootaddr, bootline,
-			max(strlen(bootline), 255));
-		flush_cache(bootaddr, max(strlen(bootline), 255));
+		memcpy((void *)bootaddr, bootline,
+		       max(strlen(bootline), (size_t)255));
+		flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
 	} else {
 		sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
 		tmp = getenv("bootfile");
@@ -240,9 +240,9 @@
 			 CONFIG_SYS_VXWORKS_ADD_PARAMS);
 #endif
 
-		memcpy((void *) bootaddr, build_buf,
-			max(strlen(build_buf), 255));
-		flush_cache(bootaddr, max(strlen(build_buf), 255));
+		memcpy((void *)bootaddr, build_buf,
+		       max(strlen(build_buf), (size_t)255));
+		flush_cache(bootaddr, max(strlen(build_buf), (size_t)255));
 	}
 
 	/*
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 95a6f89..5c788e9 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -18,7 +18,6 @@
 
 static struct spi_flash *flash;
 
-
 /*
  * This function computes the length argument for the erase command.
  * The length on which the command is to operate can be given in two forms:
@@ -71,9 +70,9 @@
 {
 	/* less accurate but avoids overflow */
 	if (len >= ((unsigned int) -1) / 1024)
-		return len / (max(get_timer(start_ms) / 1024, 1));
+		return len / (max(get_timer(start_ms) / 1024, 1UL));
 	else
-		return 1024 * len / max(get_timer(start_ms), 1);
+		return 1024 * len / max(get_timer(start_ms), 1UL);
 }
 
 static int do_spi_flash_probe(int argc, char * const argv[])
@@ -223,7 +222,7 @@
 		ulong last_update = get_timer(0);
 
 		for (; buf < end && !err_oper; buf += todo, offset += todo) {
-			todo = min(end - buf, flash->sector_size);
+			todo = min_t(size_t, end - buf, flash->sector_size);
 			if (get_timer(last_update) > 100) {
 				printf("   \rUpdating, %zu%% %lu B/s",
 				       100 - (end - buf) / scale,
@@ -421,7 +420,8 @@
 	for (i = 0; i < len; i++) {
 		if (vbuf[i] != 0xff) {
 			printf("Check failed at %d\n", i);
-			print_buffer(i, vbuf + i, 1, min(len - i, 0x40), 0);
+			print_buffer(i, vbuf + i, 1,
+				     min_t(uint, len - i, 0x40), 0);
 			return -1;
 		}
 	}
@@ -443,9 +443,11 @@
 	for (i = 0; i < len; i++) {
 		if (buf[i] != vbuf[i]) {
 			printf("Verify failed at %d, good data:\n", i);
-			print_buffer(i, buf + i, 1, min(len - i, 0x40), 0);
+			print_buffer(i, buf + i, 1,
+				     min_t(uint, len - i, 0x40), 0);
 			printf("Bad data:\n");
-			print_buffer(i, vbuf + i, 1, min(len - i, 0x40), 0);
+			print_buffer(i, vbuf + i, 1,
+				     min_t(uint, len - i, 0x40), 0);
 			return -1;
 		}
 	}
diff --git a/common/env_nand.c b/common/env_nand.c
index 749605f..9c9bb82 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -132,7 +132,7 @@
 	u_char *char_ptr;
 
 	blocksize = nand_info[0].erasesize;
-	len = min(blocksize, CONFIG_ENV_SIZE);
+	len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
 
 	while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
 		if (nand_block_isbad(&nand_info[0], offset)) {
@@ -244,7 +244,7 @@
 	if (!blocksize)
 		return 1;
 
-	len = min(blocksize, CONFIG_ENV_SIZE);
+	len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
 
 	while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
 		if (nand_block_isbad(&nand_info[0], offset)) {
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 3f64156..2d3c387 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -1199,7 +1199,8 @@
  */
 int fdt_alloc_phandle(void *blob)
 {
-	int offset, phandle = 0;
+	int offset;
+	uint32_t phandle = 0;
 
 	for (offset = fdt_next_node(blob, -1, NULL); offset >= 0;
 	     offset = fdt_next_node(blob, offset, NULL)) {
diff --git a/common/lcd.c b/common/lcd.c
index 37147af..d8e1371 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -746,7 +746,7 @@
 	else
 		return;
 
-	*axis = max(0, axis_alignment);
+	*axis = max(0, (int)axis_alignment);
 }
 #endif
 
@@ -1145,8 +1145,8 @@
 
 void lcd_position_cursor(unsigned col, unsigned row)
 {
-	console_col = min(col, CONSOLE_COLS - 1);
-	console_row = min(row, CONSOLE_ROWS - 1);
+	console_col = min_t(short, col, CONSOLE_COLS - 1);
+	console_row = min_t(short, row, CONSOLE_ROWS - 1);
 }
 
 int lcd_get_pixel_width(void)
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 0f1eab4..66b4a72 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -300,7 +300,8 @@
 	}
 	descriptor = (struct usb_hub_descriptor *)buffer;
 
-	length = min(descriptor->bLength, sizeof(struct usb_hub_descriptor));
+	length = min_t(int, descriptor->bLength,
+		       sizeof(struct usb_hub_descriptor));
 
 	if (usb_get_hub_descriptor(dev, buffer, length) < 0) {
 		debug("usb_hub_configure: failed to get hub " \