linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sunxi: avoid invalid pointer calculation
@ 2015-02-24  9:47 Arnd Bergmann
  2015-02-24  9:50 ` David Lanzendörfer
  2015-03-05 13:51 ` Ulf Hansson
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2015-02-24  9:47 UTC (permalink / raw)
  To: linux-arm-kernel

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>

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index e8a4218b5726..c326ac965806 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -293,7 +293,7 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
 				    struct mmc_data *data)
 {
 	struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
-	struct sunxi_idma_des *pdes_pa = (struct sunxi_idma_des *)host->sg_dma;
+	dma_addr_t next_desc = host->sg_dma;
 	int i, max_len = (1 << host->idma_des_size_bits);
 
 	for (i = 0; i < data->sg_len; i++) {
@@ -305,8 +305,9 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
 		else
 			pdes[i].buf_size = data->sg[i].length;
 
+		next_desc += sizeof(struct sunxi_idma_des);
 		pdes[i].buf_addr_ptr1 = sg_dma_address(&data->sg[i]);
-		pdes[i].buf_addr_ptr2 = (u32)&pdes_pa[i + 1];
+		pdes[i].buf_addr_ptr2 = (u32)next_desc;
 	}
 
 	pdes[0].config |= SDXC_IDMAC_DES0_FD;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] mmc: sunxi: avoid invalid pointer calculation
  2015-02-24  9:47 [PATCH] mmc: sunxi: avoid invalid pointer calculation Arnd Bergmann
@ 2015-02-24  9:50 ` David Lanzendörfer
  2015-03-05 13:51 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: David Lanzendörfer @ 2015-02-24  9:50 UTC (permalink / raw)
  To: linux-arm-kernel

Acked-by: David Lanzend?rfer <david.lanzendoerfer@o2s.ch>

Am Dienstag, 24. Februar 2015, 10.47:27 schrieb Arnd Bergmann:
> 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>
> 
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index e8a4218b5726..c326ac965806 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -293,7 +293,7 @@ static void sunxi_mmc_init_idma_des(struct
> sunxi_mmc_host *host, struct mmc_data *data)
>  {
>  	struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
> -	struct sunxi_idma_des *pdes_pa = (struct sunxi_idma_des *)host->sg_dma;
> +	dma_addr_t next_desc = host->sg_dma;
>  	int i, max_len = (1 << host->idma_des_size_bits);
> 
>  	for (i = 0; i < data->sg_len; i++) {
> @@ -305,8 +305,9 @@ static void sunxi_mmc_init_idma_des(struct
> sunxi_mmc_host *host, else
>  			pdes[i].buf_size = data->sg[i].length;
> 
> +		next_desc += sizeof(struct sunxi_idma_des);
>  		pdes[i].buf_addr_ptr1 = sg_dma_address(&data->sg[i]);
> -		pdes[i].buf_addr_ptr2 = (u32)&pdes_pa[i + 1];
> +		pdes[i].buf_addr_ptr2 = (u32)next_desc;
>  	}
> 
>  	pdes[0].config |= SDXC_IDMAC_DES0_FD;

-- 
David Lanzend?rfer
OpenSourceSupport GmbH
System engineer and supporter
http://www.o2s.ch/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150224/f5d895ea/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] mmc: sunxi: avoid invalid pointer calculation
  2015-02-24  9:47 [PATCH] mmc: sunxi: avoid invalid pointer calculation Arnd Bergmann
  2015-02-24  9:50 ` David Lanzendörfer
@ 2015-03-05 13:51 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2015-03-05 13:51 UTC (permalink / raw)
  To: linux-arm-kernel

On 24 February 2015 at 10:47, Arnd Bergmann <arnd@arndb.de> wrote:
> 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>

Applied, thanks!

Kind regards
Uffe


>
> diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
> index e8a4218b5726..c326ac965806 100644
> --- a/drivers/mmc/host/sunxi-mmc.c
> +++ b/drivers/mmc/host/sunxi-mmc.c
> @@ -293,7 +293,7 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
>                                     struct mmc_data *data)
>  {
>         struct sunxi_idma_des *pdes = (struct sunxi_idma_des *)host->sg_cpu;
> -       struct sunxi_idma_des *pdes_pa = (struct sunxi_idma_des *)host->sg_dma;
> +       dma_addr_t next_desc = host->sg_dma;
>         int i, max_len = (1 << host->idma_des_size_bits);
>
>         for (i = 0; i < data->sg_len; i++) {
> @@ -305,8 +305,9 @@ static void sunxi_mmc_init_idma_des(struct sunxi_mmc_host *host,
>                 else
>                         pdes[i].buf_size = data->sg[i].length;
>
> +               next_desc += sizeof(struct sunxi_idma_des);
>                 pdes[i].buf_addr_ptr1 = sg_dma_address(&data->sg[i]);
> -               pdes[i].buf_addr_ptr2 = (u32)&pdes_pa[i + 1];
> +               pdes[i].buf_addr_ptr2 = (u32)next_desc;
>         }
>
>         pdes[0].config |= SDXC_IDMAC_DES0_FD;
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-05 13:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-24  9:47 [PATCH] mmc: sunxi: avoid invalid pointer calculation Arnd Bergmann
2015-02-24  9:50 ` David Lanzendörfer
2015-03-05 13:51 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).