linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: core: Protect DMA code by #ifdef CONFIG_HAS_DMA
@ 2014-05-02  4:29 Geert Uytterhoeven
       [not found] ` <1399004974-19566-1-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2014-05-02  4:29 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Geert Uytterhoeven

If NO_DMA=y:

drivers/built-in.o: In function `spi_map_buf':
spi.c:(.text+0x21bc60): undefined reference to `dma_map_sg'
drivers/built-in.o: In function `spi_unmap_buf.isra.33':
spi.c:(.text+0x21c32e): undefined reference to `dma_unmap_sg'
make[3]: *** [vmlinux] Error 1

Protect the DMA code by #ifdef CONFIG_HAS_DMA to fix this:
  - Extract __spi_map_msg() from spi_map_msg(),
  - Provide dummy definitions of __spi_map_msg() and spi_unmap_msg() if
    !CONFIG_HAS_DMA.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/spi/spi.c |  109 ++++++++++++++++++++++++++++++++---------------------
 1 file changed, 65 insertions(+), 44 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 4eb9bf02996c..341942b640e1 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -580,6 +580,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
 		spi->master->set_cs(spi, !enable);
 }
 
+#ifdef CONFIG_HAS_DMA
 static int spi_map_buf(struct spi_master *master, struct device *dev,
 		       struct sg_table *sgt, void *buf, size_t len,
 		       enum dma_data_direction dir)
@@ -637,55 +638,12 @@ static void spi_unmap_buf(struct spi_master *master, struct device *dev,
 	}
 }
 
-static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
+static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)
 {
 	struct device *tx_dev, *rx_dev;
 	struct spi_transfer *xfer;
-	void *tmp;
-	unsigned int max_tx, max_rx;
 	int ret;
 
-	if (master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) {
-		max_tx = 0;
-		max_rx = 0;
-
-		list_for_each_entry(xfer, &msg->transfers, transfer_list) {
-			if ((master->flags & SPI_MASTER_MUST_TX) &&
-			    !xfer->tx_buf)
-				max_tx = max(xfer->len, max_tx);
-			if ((master->flags & SPI_MASTER_MUST_RX) &&
-			    !xfer->rx_buf)
-				max_rx = max(xfer->len, max_rx);
-		}
-
-		if (max_tx) {
-			tmp = krealloc(master->dummy_tx, max_tx,
-				       GFP_KERNEL | GFP_DMA);
-			if (!tmp)
-				return -ENOMEM;
-			master->dummy_tx = tmp;
-			memset(tmp, 0, max_tx);
-		}
-
-		if (max_rx) {
-			tmp = krealloc(master->dummy_rx, max_rx,
-				       GFP_KERNEL | GFP_DMA);
-			if (!tmp)
-				return -ENOMEM;
-			master->dummy_rx = tmp;
-		}
-
-		if (max_tx || max_rx) {
-			list_for_each_entry(xfer, &msg->transfers,
-					    transfer_list) {
-				if (!xfer->tx_buf)
-					xfer->tx_buf = master->dummy_tx;
-				if (!xfer->rx_buf)
-					xfer->rx_buf = master->dummy_rx;
-			}
-		}
-	}
-
 	if (!master->can_dma)
 		return 0;
 
@@ -742,6 +700,69 @@ static int spi_unmap_msg(struct spi_master *master, struct spi_message *msg)
 
 	return 0;
 }
+#else /* !CONFIG_HAS_DMA */
+static inline int __spi_map_msg(struct spi_master *master,
+				struct spi_message *msg)
+{
+	return 0;
+}
+
+static inline int spi_unmap_msg(struct spi_master *master,
+				struct spi_message *msg)
+{
+	return 0;
+}
+#endif /* !CONFIG_HAS_DMA */
+
+static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
+{
+	struct spi_transfer *xfer;
+	void *tmp;
+	unsigned int max_tx, max_rx;
+
+	if (master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) {
+		max_tx = 0;
+		max_rx = 0;
+
+		list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+			if ((master->flags & SPI_MASTER_MUST_TX) &&
+			    !xfer->tx_buf)
+				max_tx = max(xfer->len, max_tx);
+			if ((master->flags & SPI_MASTER_MUST_RX) &&
+			    !xfer->rx_buf)
+				max_rx = max(xfer->len, max_rx);
+		}
+
+		if (max_tx) {
+			tmp = krealloc(master->dummy_tx, max_tx,
+				       GFP_KERNEL | GFP_DMA);
+			if (!tmp)
+				return -ENOMEM;
+			master->dummy_tx = tmp;
+			memset(tmp, 0, max_tx);
+		}
+
+		if (max_rx) {
+			tmp = krealloc(master->dummy_rx, max_rx,
+				       GFP_KERNEL | GFP_DMA);
+			if (!tmp)
+				return -ENOMEM;
+			master->dummy_rx = tmp;
+		}
+
+		if (max_tx || max_rx) {
+			list_for_each_entry(xfer, &msg->transfers,
+					    transfer_list) {
+				if (!xfer->tx_buf)
+					xfer->tx_buf = master->dummy_tx;
+				if (!xfer->rx_buf)
+					xfer->rx_buf = master->dummy_rx;
+			}
+		}
+	}
+
+	return __spi_map_msg(master, msg);
+}
 
 /*
  * spi_transfer_one_message - Default implementation of transfer_one_message()
-- 
1.7.9.5

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

* Re: [PATCH] spi: core: Protect DMA code by #ifdef CONFIG_HAS_DMA
       [not found] ` <1399004974-19566-1-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
@ 2014-05-02 17:14   ` Mark Brown
       [not found]     ` <20140502171411.GS3245-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2014-05-02 17:14 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

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

On Fri, May 02, 2014 at 06:29:34AM +0200, Geert Uytterhoeven wrote:
> If NO_DMA=y:
> 
> drivers/built-in.o: In function `spi_map_buf':
> spi.c:(.text+0x21bc60): undefined reference to `dma_map_sg'
> drivers/built-in.o: In function `spi_unmap_buf.isra.33':
> spi.c:(.text+0x21c32e): undefined reference to `dma_unmap_sg'
> make[3]: *** [vmlinux] Error 1

Ugh.  It would seem better to have these functions stubbed out.  But
applied anyway.

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

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

* Re: [PATCH] spi: core: Protect DMA code by #ifdef CONFIG_HAS_DMA
       [not found]     ` <20140502171411.GS3245-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2014-05-02 21:09       ` Geert Uytterhoeven
       [not found]         ` <CAMuHMdW6kGfVq8y_HV7Aupa7jB9+qdtM4PYGGG54=aCi1AvRYg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2014-05-02 21:09 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

Hi Mark,

On Fri, May 2, 2014 at 7:14 PM, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> On Fri, May 02, 2014 at 06:29:34AM +0200, Geert Uytterhoeven wrote:
>> If NO_DMA=y:
>>
>> drivers/built-in.o: In function `spi_map_buf':
>> spi.c:(.text+0x21bc60): undefined reference to `dma_map_sg'
>> drivers/built-in.o: In function `spi_unmap_buf.isra.33':
>> spi.c:(.text+0x21c32e): undefined reference to `dma_unmap_sg'
>> make[3]: *** [vmlinux] Error 1
>
> Ugh.  It would seem better to have these functions stubbed out.  But

As long as we have include/asm-generic/dma-mapping-broken.h,
it'll be like this...

> applied anyway.

Thanks!

BTW, I have a few more "depends on HAS_DMA" patches lying around for
drivers...

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] spi: core: Protect DMA code by #ifdef CONFIG_HAS_DMA
       [not found]         ` <CAMuHMdW6kGfVq8y_HV7Aupa7jB9+qdtM4PYGGG54=aCi1AvRYg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-05-03  1:52           ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-05-03  1:52 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-spi, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

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

On Fri, May 02, 2014 at 11:09:18PM +0200, Geert Uytterhoeven wrote:
> On Fri, May 2, 2014 at 7:14 PM, Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:

> > Ugh.  It would seem better to have these functions stubbed out.  But

> As long as we have include/asm-generic/dma-mapping-broken.h,
> it'll be like this...

Yeah, I'm not sure that it's an ideal approach.

> BTW, I have a few more "depends on HAS_DMA" patches lying around for
> drivers...

Sure - it's good to fix these things, fire away.

[-- 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-05-03  1:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-02  4:29 [PATCH] spi: core: Protect DMA code by #ifdef CONFIG_HAS_DMA Geert Uytterhoeven
     [not found] ` <1399004974-19566-1-git-send-email-geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>
2014-05-02 17:14   ` Mark Brown
     [not found]     ` <20140502171411.GS3245-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-05-02 21:09       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdW6kGfVq8y_HV7Aupa7jB9+qdtM4PYGGG54=aCi1AvRYg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-05-03  1:52           ` Mark Brown

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).