diff mbox

spi: add spi_sync_single_transfer wrapper for single spi_transfer

Message ID 1466034046-718-1-git-send-email-andi.shyti@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andi Shyti June 15, 2016, 11:40 p.m. UTC
The spi_sync_single_transfer function calls spi_sync_transfer
with a single spi_transfer element, instead of an array.

Signed-off-by: Andi Shyti <andi.shyti@samsung.com>
---
 include/linux/spi/spi.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Lars-Peter Clausen June 16, 2016, 4:10 p.m. UTC | #1
On 06/16/2016 01:40 AM, Andi Shyti wrote:
> The spi_sync_single_transfer function calls spi_sync_transfer
> with a single spi_transfer element, instead of an array.

So, what's the advantage of using this as opposed to calling
spi_sync_transfer with a 1 for the number of transfers?
--
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
Andi Shyti June 17, 2016, 12:43 a.m. UTC | #2
Hi Lars,

> > The spi_sync_single_transfer function calls spi_sync_transfer
> > with a single spi_transfer element, instead of an array.
> 
> So, what's the advantage of using this as opposed to calling
> spi_sync_transfer with a 1 for the number of transfers?

Not much, but it keeps the code a bit nicer to read for those
using spi_sync_transfer with only one spi_transfer. Besides it's
also more understandable what the function itself does and there
would not be any need to jump into the spi_sync_transfer to check
what the number '1' is needed for (for example it's not a boolean 
'true' value).

I checked and there are quite many uses of spi_sync_transfer with
only 1 transfer.

Thanks,
Andi
--
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 June 17, 2016, 11:34 a.m. UTC | #3
On Fri, Jun 17, 2016 at 09:43:11AM +0900, Andi Shyti wrote:

> > > The spi_sync_single_transfer function calls spi_sync_transfer
> > > with a single spi_transfer element, instead of an array.

> > So, what's the advantage of using this as opposed to calling
> > spi_sync_transfer with a 1 for the number of transfers?

> Not much, but it keeps the code a bit nicer to read for those
> using spi_sync_transfer with only one spi_transfer. Besides it's
> also more understandable what the function itself does and there
> would not be any need to jump into the spi_sync_transfer to check
> what the number '1' is needed for (for example it's not a boolean 
> 'true' value).

I really don't think this has been a big source of confusion for people.
Andi Shyti June 17, 2016, 11:38 a.m. UTC | #4
On Fri, Jun 17, 2016 at 12:34:53PM +0100, Mark Brown wrote:
> On Fri, Jun 17, 2016 at 09:43:11AM +0900, Andi Shyti wrote:
> 
> > > > The spi_sync_single_transfer function calls spi_sync_transfer
> > > > with a single spi_transfer element, instead of an array.
> 
> > > So, what's the advantage of using this as opposed to calling
> > > spi_sync_transfer with a 1 for the number of transfers?
> 
> > Not much, but it keeps the code a bit nicer to read for those
> > using spi_sync_transfer with only one spi_transfer. Besides it's
> > also more understandable what the function itself does and there
> > would not be any need to jump into the spi_sync_transfer to check
> > what the number '1' is needed for (for example it's not a boolean 
> > 'true' value).
> 
> I really don't think this has been a big source of confusion for people.

OK, nevermind, then :)

Thanks,
Andi
--
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/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 1f03483..660f6a1 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1051,6 +1051,24 @@  spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers,
 	return spi_sync(spi, &msg);
 }
 
+/**
+ * spi_sync_single_transfer - synchronous SPI data transfer of one spi_transfer
+ * @spi: device with which data will be exchanged
+ * @xfers: One spi_transfer struct
+ * Context: can sleep
+ *
+ * Does a synchronous SPI data transfer of a given spi_transfer.
+ *
+ * For more specific semantics see spi_sync_transfer().
+ *
+ * It returns zero on success, else a negative error code.
+ */
+static inline int
+spi_sync_single_transfer(struct spi_device *spi, struct spi_transfer *xfers)
+{
+	return spi_sync_transfer(spi, xfers, 1);
+}
+
 /* this copies txbuf and rxbuf data; for small transfers only! */
 extern int spi_write_then_read(struct spi_device *spi,
 		const void *txbuf, unsigned n_tx,