All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] spi: core: Fix check for dma_map_sg() failures
@ 2014-07-10 13:29 Geert Uytterhoeven
  2014-07-10 13:29 ` [PATCH 2/2] [RFC] spi: core: Pass correct device to dma_map_sg() Geert Uytterhoeven
  2014-07-11 12:57   ` Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2014-07-10 13:29 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, dmaengine, linux-kernel, Geert Uytterhoeven

From: Geert Uytterhoeven <geert+renesas@glider.be>

According to Documentation/DMA-API.txt, dma_map_sg() returns 0 on failure.
As spi_map_buf() returns an error code, convert zero into -ENOMEM.
Keep the existing check for negative numbers just in case.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/spi/spi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3a3245dd64ed..3aac0e885cd9 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -617,6 +617,8 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
 	}
 
 	ret = dma_map_sg(dev, sgt->sgl, sgt->nents, dir);
+	if (!ret)
+		ret = -ENOMEM;
 	if (ret < 0) {
 		sg_free_table(sgt);
 		return ret;
-- 
1.9.1


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

* [PATCH 2/2] [RFC] spi: core: Pass correct device to dma_map_sg()
  2014-07-10 13:29 [PATCH 1/2] spi: core: Fix check for dma_map_sg() failures Geert Uytterhoeven
@ 2014-07-10 13:29 ` Geert Uytterhoeven
  2014-07-11 12:57   ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2014-07-10 13:29 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, dmaengine, linux-kernel, Geert Uytterhoeven

From: Geert Uytterhoeven <geert+renesas@glider.be>

According to Documentation/dmaengine.txt, scatterlists must be mapped
using the DMA struct device.

However, "dma_chan.dev->device" is the sysfs class device's device.
Use "dma_chan.device->dev" instead, which is the real DMA device's device.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
It seems very few drivers pass the right device.  Most drivers pass the
platform device's device, cfr. Documentation/DMA-API-HOWTO.txt, which
suggests to use "&my_dev->dev".

Question: If dma_map_*() is called with the DMA struct device, I assume
          dma_sync_() should also be called with the same DMA struct
	  device?
---
 drivers/spi/spi.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3aac0e885cd9..eef58cec2210 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -647,8 +647,8 @@ static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)
 	if (!master->can_dma)
 		return 0;
 
-	tx_dev = &master->dma_tx->dev->device;
-	rx_dev = &master->dma_rx->dev->device;
+	tx_dev = master->dma_tx->device->dev;
+	rx_dev = master->dma_rx->device->dev;
 
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
 		if (!master->can_dma(master, msg->spi, xfer))
@@ -687,8 +687,8 @@ static int spi_unmap_msg(struct spi_master *master, struct spi_message *msg)
 	if (!master->cur_msg_mapped || !master->can_dma)
 		return 0;
 
-	tx_dev = &master->dma_tx->dev->device;
-	rx_dev = &master->dma_rx->dev->device;
+	tx_dev = master->dma_tx->device->dev;
+	rx_dev = master->dma_rx->device->dev;
 
 	list_for_each_entry(xfer, &msg->transfers, transfer_list) {
 		if (!master->can_dma(master, msg->spi, xfer))
-- 
1.9.1


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

* Re: [PATCH 1/2] spi: core: Fix check for dma_map_sg() failures
@ 2014-07-11 12:57   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-07-11 12:57 UTC (permalink / raw)
  To: Geert Uytterhoeven; +Cc: linux-spi, dmaengine, linux-kernel, Geert Uytterhoeven

[-- Attachment #1: Type: text/plain, Size: 362 bytes --]

On Thu, Jul 10, 2014 at 03:29:32PM +0200, Geert Uytterhoeven wrote:
> From: Geert Uytterhoeven <geert+renesas@glider.be>
> 
> According to Documentation/DMA-API.txt, dma_map_sg() returns 0 on failure.
> As spi_map_buf() returns an error code, convert zero into -ENOMEM.
> Keep the existing check for negative numbers just in case.

Applied both, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 1/2] spi: core: Fix check for dma_map_sg() failures
@ 2014-07-11 12:57   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-07-11 12:57 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	dmaengine-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Geert Uytterhoeven

[-- Attachment #1: Type: text/plain, Size: 392 bytes --]

On Thu, Jul 10, 2014 at 03:29:32PM +0200, Geert Uytterhoeven wrote:
> From: Geert Uytterhoeven <geert+renesas-gXvu3+zWzMSzQB+pC5nmwQ@public.gmane.org>
> 
> According to Documentation/DMA-API.txt, dma_map_sg() returns 0 on failure.
> As spi_map_buf() returns an error code, convert zero into -ENOMEM.
> Keep the existing check for negative numbers just in case.

Applied both, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

end of thread, other threads:[~2014-07-11 13:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-10 13:29 [PATCH 1/2] spi: core: Fix check for dma_map_sg() failures Geert Uytterhoeven
2014-07-10 13:29 ` [PATCH 2/2] [RFC] spi: core: Pass correct device to dma_map_sg() Geert Uytterhoeven
2014-07-11 12:57 ` [PATCH 1/2] spi: core: Fix check for dma_map_sg() failures Mark Brown
2014-07-11 12:57   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.