Re: [PATCH 2/2][RFC] mmc: cast unsigned int to typeof(sector_t) to avoid unexpected error

From: Kuninori Morimoto
Date: Wed Apr 08 2015 - 05:15:00 EST


Hi

> card->csd.capacity is defined as "unsigned int",
> and, sector_t is defined as "u64" or "unsigned long" (depends on CONFIG_LBDAF)
> sector_t data might have strange data if first bit of unsigned int
> was 1. this patch cast it to typeof(sector_t)
>
> ex) if sector_t was u64
>
> unsigned int data;
> sector_t sector;
>
> data = 0x80000000;
> sector = (data << 8); // 0xffffff8000000000
> sector = (((typeof(sector_t))data) << 8); // 0x8000000000

Sorry, I noticed this explain (= number of 0) was wrong
Maybe it should be

data = 0x800000;
sector = (data << 8); // 0xffffffff80000000
sector = (((typeof(sector_t))data) << 8); // 0x80000000

or

data = 0x80000000;
sector = (data << 8); // 0x0
sector = (((typeof(sector_t))data) << 8); // 0x8000000000
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/