diff mbox

[1/1] spi: altera: Add empty implementation of setup_transfer callback

Message ID 1428591822-24279-2-git-send-email-per.nilsson@xelmo.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pelle Nilsson April 9, 2015, 3:03 p.m. UTC
This callback is mandatory since txrx_bufs callback is defined. The lack of
it causes a kernel panic on first SPI transaction.

Signed-off-by: Pelle Nilsson <per.nilsson@xelmo.com>
---
 drivers/spi/spi-altera.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Mark Brown April 9, 2015, 3:40 p.m. UTC | #1
On Thu, Apr 09, 2015 at 05:03:42PM +0200, Pelle Nilsson wrote:

> This callback is mandatory since txrx_bufs callback is defined. The lack of
> it causes a kernel panic on first SPI transaction.

Why is the callback mandatory if an empty implementation is OK?
Pelle Nilsson April 9, 2015, 3:50 p.m. UTC | #2
On 2015-04-09 17:40, Mark Brown wrote:
> Why is the callback mandatory if an empty implementation is OK?

Ask the author of spi-bitbang. :-)

In spi_bitbang_start() we have this chunk of code:

	if (!bitbang->txrx_bufs) {
		bitbang->use_dma = 0;
		bitbang->txrx_bufs = spi_bitbang_bufs;
		if (!master->setup) {
			if (!bitbang->setup_transfer)
				bitbang->setup_transfer =
					 spi_bitbang_setup_transfer;
			master->setup = spi_bitbang_setup;
			master->cleanup = spi_bitbang_cleanup;
		}
	}

As can be seen here, if setup_transfer is NULL (not set by the
specific driver), it is filled in with the default callback function
spi_bitbang_setup_transfer(), but only if txrx_bufs is also NULL,
which is not the case here.

There is a comment in spi-xilinx also stating this fact (though their
implementation isn't actually empty anymore):

/* spi_bitbang requires custom setup_transfer() to be defined if there
is a
 * custom txrx_bufs().
 */
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mark Brown April 9, 2015, 4:10 p.m. UTC | #3
On Thu, Apr 09, 2015 at 05:50:52PM +0200, Pelle Nilsson wrote:
> On 2015-04-09 17:40, Mark Brown wrote:
> > Why is the callback mandatory if an empty implementation is OK?

> Ask the author of spi-bitbang. :-)

What I'm trying to suggest is that you're perhaps fixing the wrong
problem - make the callback optional if there's a good reason for it.
Why is this patch the best fix?
Pelle Nilsson April 13, 2015, 9:45 a.m. UTC | #4
On 2015-04-09 18:10, Mark Brown wrote:
> On Thu, Apr 09, 2015 at 05:50:52PM +0200, Pelle Nilsson wrote: What
> I'm trying to suggest is that you're perhaps fixing the wrong 
> problem - make the callback optional if there's a good reason for
> it.

Yes, the callback can be made optional, I'll send a new patch.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/spi/spi-altera.c b/drivers/spi/spi-altera.c
index b95010e..6d72b1d 100644
--- a/drivers/spi/spi-altera.c
+++ b/drivers/spi/spi-altera.c
@@ -197,6 +197,11 @@  static irqreturn_t altera_spi_irq(int irq, void *dev)
 	return IRQ_HANDLED;
 }
 
+static int altera_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
+{
+	return 0;
+}
+
 static int altera_spi_probe(struct platform_device *pdev)
 {
 	struct altera_spi *hw;
@@ -220,6 +225,7 @@  static int altera_spi_probe(struct platform_device *pdev)
 
 	/* setup the state for the bitbang driver */
 	hw->bitbang.master = master;
+	hw->bitbang.setup_transfer = altera_spi_setupxfer;
 	hw->bitbang.chipselect = altera_spi_chipsel;
 	hw->bitbang.txrx_bufs = altera_spi_txrx;