Patchwork [2/5] RBTX4939: Add MTD support

login
register
mail settings
Submitter Andrew Morton
Date Jan. 27, 2009, 9:14 p.m.
Message ID <20090127131454.d2f147df.akpm@linux-foundation.org>
Download mbox | patch
Permalink /patch/20513/
State New
Headers show

Comments

Andrew Morton - Jan. 27, 2009, 9:14 p.m.
On Tue, 20 Jan 2009 23:12:16 +0900
Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:

> +static void rbtx4939_flash_copy_from(struct map_info *map, void *to,
> +				     unsigned long from, ssize_t len)
> +{
> +	u8 bdipsw = readb(rbtx4939_bdipsw_addr) & 0x0f;
> +	unsigned char shift;
> +	ssize_t curlen;
> +
> +	from += (unsigned long)map->virt;
> +	if (bdipsw & 8) {
> +		/* BOOT Mode: USER ROM1 / USER ROM2 */
> +		shift = bdipsw & 3;
> +		while (len) {
> +			curlen = min((unsigned long)len,
> +				     0x400000 -	(from & (0x400000 - 1)));
> +			memcpy(to,
> +			       (void *)((from & ~0xc00000) |
> +					((((from >> 22) + shift) & 3) << 22)),
> +			       curlen);
> +			len -= curlen;
> +			from += curlen;
> +			to += curlen;
> +		}
> +		return;
> +	}
> +#ifdef __BIG_ENDIAN
> +	if (bdipsw == 0) {
> +		/* BOOT Mode: Monitor ROM */
> +		while (len) {
> +			curlen = min((unsigned long)len,
> +				     0x400000 - (from & (0x400000 - 1)));
> +			memcpy(to, (void *)(from ^ 0x400000), curlen);
> +			len -= curlen;
> +			from += curlen;
> +			to += curlen;
> +		}
> +		return;
> +	}
> +#endif
> +	memcpy(to, (void *)from, len);
> +}

min_t is the preferred way of preventing that warning.

Well.  Actually the preferred way is to get the types right - often the
code simply goofed, and people use casts/min_t to hide that.  But in
this case, yes, casting literal constants to ssize_t would be a bit
silly.

Patch

--- a/arch/mips/txx9/rbtx4939/setup.c~mtd-rbtx4939-add-mtd-support-fix
+++ a/arch/mips/txx9/rbtx4939/setup.c
@@ -335,7 +335,7 @@  static void rbtx4939_flash_copy_from(str
 		/* BOOT Mode: USER ROM1 / USER ROM2 */
 		shift = bdipsw & 3;
 		while (len) {
-			curlen = min((unsigned long)len,
+			curlen = min_t(unsigned long, len,
 				     0x400000 -	(from & (0x400000 - 1)));
 			memcpy(to,
 			       (void *)((from & ~0xc00000) |
@@ -351,7 +351,7 @@  static void rbtx4939_flash_copy_from(str
 	if (bdipsw == 0) {
 		/* BOOT Mode: Monitor ROM */
 		while (len) {
-			curlen = min((unsigned long)len,
+			curlen = min_t(unsigned long, len,
 				     0x400000 - (from & (0x400000 - 1)));
 			memcpy(to, (void *)(from ^ 0x400000), curlen);
 			len -= curlen;