[U-Boot] [PATCH 2/5] sf: sf_dataflash: Add error handler when flash operate fail

Haikun Wang haikun.wang at freescale.com
Thu Jul 2 11:12:49 CEST 2015


Add error handler when write/erase flash fail.

Signed-off-by: Haikun Wang <haikun.wang at freescale.com>
---
 drivers/mtd/spi/sf_dataflash.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/spi/sf_dataflash.c b/drivers/mtd/spi/sf_dataflash.c
index f83f994..8f91527 100644
--- a/drivers/mtd/spi/sf_dataflash.c
+++ b/drivers/mtd/spi/sf_dataflash.c
@@ -174,13 +174,14 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len)
 		status = spi_flash_cmd_write(spi, command, 4, NULL, 0);
 		if (status < 0) {
 			debug("%s: erase send command error!\n", dev->name);
-			return -EIO;
+			status = -EIO;
+			goto release_bus;
 		}
 
 		status = dataflash_waitready(spi);
 		if (status < 0) {
 			debug("%s: erase waitready error!\n", dev->name);
-			return status;
+			goto release_bus;
 		}
 
 		if (do_block) {
@@ -195,6 +196,11 @@ static int spi_dataflash_erase(struct udevice *dev, u32 offset, size_t len)
 	spi_release_bus(spi);
 
 	return 0;
+
+release_bus:
+	spi_release_bus(spi);
+
+	return status;
 }
 
 /*
@@ -329,14 +335,15 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,
 			if (status < 0) {
 				debug("%s: write(<pagesize) command error!\n",
 				      dev->name);
-				return -EIO;
+				status = -EIO;
+				goto release_bus;
 			}
 
 			status = dataflash_waitready(spi);
 			if (status < 0) {
 				debug("%s: write(<pagesize) waitready error!\n",
 				      dev->name);
-				return status;
+				goto release_bus;
 			}
 		}
 
@@ -354,13 +361,14 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,
 					     4, writebuf, writelen);
 		if (status < 0) {
 			debug("%s: write send command error!\n", dev->name);
-			return -EIO;
+			status = -EIO;
+			goto release_bus;
 		}
 
 		status = dataflash_waitready(spi);
 		if (status < 0) {
 			debug("%s: write waitready error!\n", dev->name);
-			return status;
+			goto release_bus;
 		}
 
 #ifdef CONFIG_SPI_DATAFLASH_WRITE_VERIFY
@@ -379,7 +387,8 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,
 		if (status < 0) {
 			debug("%s: write(compare) send command error!\n",
 			      dev->name);
-			return -EIO;
+			status = -EIO;
+			goto release_bus;
 		}
 
 		status = dataflash_waitready(spi);
@@ -390,7 +399,7 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,
 			       pageaddr, status);
 			remaining = 0;
 			status = -EIO;
-			break;
+			goto release_bus;
 		} else {
 			status = 0;
 		}
@@ -410,6 +419,11 @@ int spi_dataflash_write(struct udevice *dev, u32 offset, size_t len,
 	spi_release_bus(spi);
 
 	return 0;
+
+release_bus:
+	spi_release_bus(spi);
+
+	return status;
 }
 
 static int add_dataflash(struct udevice *dev, char *name, int nr_pages,
-- 
2.1.0.27.g96db324



More information about the U-Boot mailing list