Skip to contentSkip to conversation

SPI: fix return value for spi_read and spi_write

RFC PATCH In review Marc Pignat 2 participants 4 messages Oct 18, 2007 – Oct 25, 2007 2 messages not in the archive SPI

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 SPI: fix return value for spi_read and spi_write

spi_read and spi_write functions don't report late errors, for instance fifo underrun.

---

Hi all!

spi_read and spi_write should not only report errors from spi_sync, but also from message->status when spi_sync worked.

Regards

Marc

linux/spi/spi.h renamed from linux/spi/spi.h.orig +10 -2
@@ -593,6 +593,7 @@ extern int spi_sync(struct spi_device *s
 static inline int
 spi_write(struct spi_device *spi, const u8 *buf, size_t len)
 {
+	int status;
 	struct spi_transfer	t = {
 			.tx_buf		= buf,
 			.len		= len,
@@ -601,7 +602,10 @@ spi_write(struct spi_device *spi, const 
 
 	spi_message_init(&m);
 	spi_message_add_tail(&t, &m);
-	return spi_sync(spi, &m);
+
+	status = spi_sync(spi, &m);
+
+	return (status) ? status : m.status;
 }
 
 /**
@@ -617,6 +621,7 @@ spi_write(struct spi_device *spi, const 
 static inline int
 spi_read(struct spi_device *spi, u8 *buf, size_t len)
 {
+	int status;
 	struct spi_transfer	t = {
 			.rx_buf		= buf,
 			.len		= len,
@@ -625,7 +630,10 @@ spi_read(struct spi_device *spi, u8 *buf
 
 	spi_message_init(&m);
 	spi_message_add_tail(&t, &m);
-	return spi_sync(spi, &m);
+
+	status = spi_sync(spi, &m);
+
+	return (status) ? status : m.status;
 }
 
 /* this copies txbuf and rxbuf data; for small transfers only! */

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 9 lines

From: Marc Pignat <[email protected]>
Date: Thu, 18 Oct 2007 18:40:38 +0200

spi_read and spi_write functions don't report late errors, for instance fifo underrun.

---

Seems right to me. This aspect of the spi_sync() calling convention can be annoying and error-prone. I've sometimes thought about changing that instead of auditing all callers.

Are there any comments from others on this list? Which approach would be preferred: fixing callers (this is at least a partial fix for that) or updating spi_sync() so that callers don't need to check m->status?

- Dave

Quoted 33 lines
linux/spi/spi.h renamed from linux/spi/spi.h.orig +6 -1
@@ -593,6 +593,7 @@ extern int spi_sync(struct spi_device *s
 static inline int
 spi_write(struct spi_device *spi, const u8 *buf, size_t len)
 {
+	int status;
 	struct spi_transfer	t = {
 			.tx_buf		= buf,
 			.len		= len,
@@ -601,7 +602,10 @@ spi_write(struct spi_device *spi, const 
 
 	spi_message_init(&m);
 	spi_message_add_tail(&t, &m);
-	return spi_sync(spi, &m);
+
+	status = spi_sync(spi, &m);
+
+	return (status) ? status : m.status;
 }
 
 /**
@@ -617,6 +621,7 @@ spi_write(struct spi_device *spi, const 
 static inline int
 spi_read(struct spi_device *spi, u8 *buf, size_t len)
 {
+	int status;
 	struct spi_transfer	t = {
 			.rx_buf		= buf,
 			.len		= len,
@@ -625,7 +630,10 @@ spi_read(struct spi_device *spi, u8 *buf
 

linux/spi/spi.h spi_read(struct spi_device *spi, u8 *buf · line 639

Quoted 10 lines
linux/spi/spi.h renamed from linux/spi/spi.h.orig +4 -1
 	spi_message_init(&m);
 	spi_message_add_tail(&t, &m);
-	return spi_sync(spi, &m);
+
+	status = spi_sync(spi, &m);
+
+	return (status) ? status : m.status;
 }
 
 /* this copies txbuf and rxbuf data; for small transfers only! */

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

A message that is not in the archive (sent off-list or not yet received): 20071019171619.ADB4C23BF09-ZcXrCSuhvln6VZ3dlLfH/[email protected]

#4 lore raw

Hi!

Quoted 1 line · David Brownell
Quoted 1 line

From: Marc Pignat <[email protected]>

...

Quoted 10 lines

Seems right to me. This aspect of the spi_sync() calling convention can be annoying and error-prone. I've sometimes thought about changing that instead of auditing all callers.

Are there any comments from others on this list? Which approach would be preferred: fixing callers (this is at least a partial fix for that) or updating spi_sync() so that callers don't need to check m->status?

- Dave

The API will be simpler with an updated spi_sync().

Regards

Marc

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

#5 lore raw
In reply to a message not in the archive

Hi Dave!

Quoted 10 lines · David Brownell
Quoted 9 lines

From: Marc Pignat <[email protected]>
Date: Thu, 18 Oct 2007 18:40:38 +0200

spi_read and spi_write functions don't report late errors, for instance fifo underrun.

---

Quoted 9 lines

Seems right to me. This aspect of the spi_sync() calling convention can be annoying and error-prone. I've sometimes thought about changing that instead of auditing all callers.

Are there any comments from others on this list? Which approach would be preferred: fixing callers (this is at least a partial fix for that) or updating spi_sync() so that callers don't need to check m->status?

Here is a list of files using spi_sync (as in 2.6.23.1):
check only return value, does not check m->status:
drivers/mtd/devices/m25p80.c drivers/mtd/devices/mtd_dataflash.c drivers/spi/tle62x0.c
drivers/spi/spidev.c
drivers/spi/at25.c
include/linux/spi.h

read both return value and m->status, but does some unnecessary code when status!=0 drivers/rtc/rtc-max6902.c
drivers/spi/spi.c
drivers/input/touchscreen/ads7846.c

My conclusions:
* I can't find any spi_sync user wich does The Right Think(TM)
* We should fix spi_sync (and not the callers), so forget the this patch and wait for the next one!

Regards

Marc

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/