Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 087de9ed authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Ulf Hansson
Browse files

mmc: cast unsigned int to typeof(sector_t) to avoid unexpected error

card->csd.capacity is defined as "unsigned int", and sector_t is defined as
"u64" or "unsigned long" (depends on CONFIG_LBDAF). Thus, sector_t data
might have strange data (see below). This patch cast it to typeof(sector_t)
Special thanks to coverity <http://www.coverity.com

>

ex) if sector_t was u64

        unsigned int data;
        sector_t sector;

        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

Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent ded8a5f9
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2229,7 +2229,8 @@ 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,