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

From: Kuninori Morimoto
Date: Wed Apr 08 2015 - 03:33:55 EST


From: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>

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

Reported-by: coverity <http://www.coverity.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx>
---
drivers/mmc/card/block.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index c69afb5..4d09b0c 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -2205,7 +2205,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
* The CSD capacity field is in units of read_blkbits.
* set_capacity takes units of 512 bytes.
*/
- size = card->csd.capacity << (card->csd.read_blkbits - 9);
+ size = (typeof(sector_t))card->csd.capacity << (card->csd.read_blkbits - 9);
}

return mmc_blk_alloc_req(card, &card->dev, size, false, NULL,
--
1.9.1

--
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/