[PATCH 2/7] staging/wilc1000: Sanitize linux_spi_write_read
Janosch Frank
kernel at janosch-frank.de
Sun Jan 10 17:48:03 UTC 2016
Removed unneeded newlines.
Improved control flow to get rid of indents.
Added additional error message and improved existing ones.
Signed-off-by: Janosch Frank <kernel at janosch-frank.de>
---
drivers/staging/wilc1000/linux_wlan_spi.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/wilc1000/linux_wlan_spi.c b/drivers/staging/wilc1000/linux_wlan_spi.c
index 72230d2..595e274 100644
--- a/drivers/staging/wilc1000/linux_wlan_spi.c
+++ b/drivers/staging/wilc1000/linux_wlan_spi.c
@@ -289,25 +289,27 @@ int linux_spi_read(u8 *rb, u32 rlen)
int linux_spi_write_read(u8 *wb, u8 *rb, u32 rlen)
{
-
int ret;
struct spi_message msg;
struct spi_transfer tr;
- if (rlen > 0) {
- linux_spi_msg_init(&msg, &tr, rlen, wb, rb);
+ if (!rlen) {
+ PRINT_ER("Zero length read/write.\n");
+ return 0;
+ }
- ret = spi_sync(wilc_spi_dev, &msg);
- if (ret < 0) {
- PRINT_ER("SPI transaction failed\n");
- }
- } else {
- PRINT_ER("can't read data with the following length: %u\n", rlen);
- ret = -1;
+ if (!wb || !rb) {
+ PRINT_ER("Read or write buffer NULL.\n");
+ return 0;
}
+
+ linux_spi_msg_init(&msg, &tr, rlen, wb, rb);
+ ret = spi_sync(wilc_spi_dev, &msg);
+ if (ret < 0)
+ PRINT_ER("SPI sync failed and returned %d.\n", ret);
+
/* change return value to match WILC interface */
(ret < 0) ? (ret = 0) : (ret = 1);
-
return ret;
}
--
2.5.0
More information about the devel
mailing list