Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1614516 > unrolled thread

[PATCH 3.16 11/19] mmc: sunxi: avoid invalid pointer calculation

Started byBen Hutchings <ben@decadent.org.uk>
First post2017-04-01 15:30 +0200
Last post2017-04-01 22:00 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 3.16 11/19] mmc: sunxi: avoid invalid pointer calculation Ben Hutchings <ben@decadent.org.uk> - 2017-04-01 15:30 +0200
    Re: [PATCH 3.16 11/19] mmc: sunxi: avoid invalid pointer calculation David Lanzendörfer <david.lanzendoerfer@o2s.ch> - 2017-04-01 21:00 +0200
      Re: [PATCH 3.16 11/19] mmc: sunxi: avoid invalid pointer calculation Ben Hutchings <ben@decadent.org.uk> - 2017-04-01 22:00 +0200

#1614516 — [PATCH 3.16 11/19] mmc: sunxi: avoid invalid pointer calculation

FromBen Hutchings <ben@decadent.org.uk>
Date2017-04-01 15:30 +0200
Subject[PATCH 3.16 11/19] mmc: sunxi: avoid invalid pointer calculation
Message-ID<trrgn-3fN-35@gated-at.bofh.it>
3.16.43-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Arnd Bergmann <arnd@arndb.de>

commit d34712d2e3db9b241d0484a6e3839c6b7ef9df78 upstream.

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>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 drivers/mmc/host/sunxi-mmc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -294,7 +294,7 @@ static void sunxi_mmc_init_idma_des(stru
 				    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++) {
@@ -306,8 +306,9 @@ static void sunxi_mmc_init_idma_des(stru
 		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;

[toc] | [next] | [standalone]


#1614579

FromDavid Lanzendörfer <david.lanzendoerfer@o2s.ch>
Date2017-04-01 21:00 +0200
Message-ID<trwpH-6vo-1@gated-at.bofh.it>
In reply to#1614516

[Multipart message — attachments visible in raw view] — view raw

Hi
> 3.16.43-rc1 review patch.  If anyone has any objections, please let me know.
When it has been tested on multiple Allwinner platforms and it has been 
working well, then I don't have any objections.
It's actually way more elegant than the thing I did.
Thanks a lot for the improvement!
-- 
Best regards

CEO, David Lanzendörfer
Lanceville Technology
22A, Block2, China Phoenix Mansion,
No.2008 Shennan Boulevard,
Futian District, Shenzhen 

[toc] | [prev] | [next] | [standalone]


#1614588

FromBen Hutchings <ben@decadent.org.uk>
Date2017-04-01 22:00 +0200
Message-ID<trxlL-77G-1@gated-at.bofh.it>
In reply to#1614579

[Multipart message — attachments visible in raw view] — view raw

On Sun, 2017-04-02 at 02:45 +0800, David Lanzendörfer wrote:
> Hi
> > 3.16.43-rc1 review patch.  If anyone has any objections, please let me know.
> 
> When it has been tested on multiple Allwinner platforms and it has been 
> working well, then I don't have any objections.
> It's actually way more elegant than the thing I did.
> Thanks a lot for the improvement!

I'm not in a position to test this, but it was applied upstream over 2
years ago and doesn't appear to have required any follow-up fixes.

Ben.

-- 
Ben Hutchings
It is easier to change the specification to fit the program than vice
versa.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web