Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: sunxi: avoid invalid pointer calculation

The sunxi mmc driver tries to calculate a dma address by using pointer
arithmetic, which causes a warning when dma_addr_t is wider than a pointer:

drivers/mmc/host/sunxi-mmc.c: In function 'sunxi_mmc_init_idma_des':
drivers/mmc/host/sunxi-mmc.c:296:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
struct sunxi_idma_des *pdes_pa = (struct sunxi_idma_des *)host->sg_dma;
^

To avoid this warning and to simplify the logic, this changes
the code to avoid the cast and calculate the correct address
manually. The behavior should be unchanged.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: David Lanzendörfer <david.lanzendoerfer@o2s.ch>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Arnd Bergmann and committed by
Ulf Hansson
d34712d2 5f2e097c

+3 -2
+3 -2
drivers/mmc/host/sunxi-mmc.c
··· 293 293 struct mmc_data *data) 294 294 { 295 295 struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu; 296 - struct sunxi_idma_des *pdes_pa = (struct sunxi_idma_des *)host->sg_dma; 296 + dma_addr_t next_desc = host->sg_dma; 297 297 int i, max_len = (1 << host->idma_des_size_bits); 298 298 299 299 for (i = 0; i < data->sg_len; i++) { ··· 305 305 else 306 306 pdes[i].buf_size = data->sg[i].length; 307 307 308 + next_desc += sizeof(struct sunxi_idma_des); 308 309 pdes[i].buf_addr_ptr1 = sg_dma_address(&data->sg[i]); 309 - pdes[i].buf_addr_ptr2 = (u32)&pdes_pa[i + 1]; 310 + pdes[i].buf_addr_ptr2 = (u32)next_desc; 310 311 } 311 312 312 313 pdes[0].config |= SDXC_IDMAC_DES0_FD;