0001-sf-fix-out-of-order-calls-for-spi_claim_bus-and-spi_.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. From 909840ef844013379e5ec399c1e76c65d1a6eb1d Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  3. Date: Sat, 12 Oct 2013 21:09:47 +0200
  4. Subject: sf: fix out-of-order calls for spi_claim_bus and spi_release_bus
  5. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  6. --- a/drivers/mtd/spi/sf_ops.c
  7. +++ b/drivers/mtd/spi/sf_ops.c
  8. @@ -132,12 +132,6 @@ int spi_flash_write_common(struct spi_fl
  9. if (buf == NULL)
  10. timeout = SPI_FLASH_PAGE_ERASE_TIMEOUT;
  11. - ret = spi_claim_bus(flash->spi);
  12. - if (ret) {
  13. - debug("SF: unable to claim SPI bus\n");
  14. - return ret;
  15. - }
  16. -
  17. ret = spi_flash_cmd_write_enable(flash);
  18. if (ret < 0) {
  19. debug("SF: enabling write failed\n");
  20. @@ -158,8 +152,6 @@ int spi_flash_write_common(struct spi_fl
  21. return ret;
  22. }
  23. - spi_release_bus(spi);
  24. -
  25. return ret;
  26. }
  27. @@ -175,12 +167,18 @@ int spi_flash_cmd_erase_ops(struct spi_f
  28. return -1;
  29. }
  30. + ret = spi_claim_bus(flash->spi);
  31. + if (ret) {
  32. + debug("SF: unable to claim SPI bus\n");
  33. + return ret;
  34. + }
  35. +
  36. cmd[0] = flash->erase_cmd;
  37. while (len) {
  38. #ifdef CONFIG_SPI_FLASH_BAR
  39. ret = spi_flash_bank(flash, offset);
  40. if (ret < 0)
  41. - return ret;
  42. + goto done;
  43. #endif
  44. spi_flash_addr(offset, cmd);
  45. @@ -190,13 +188,16 @@ int spi_flash_cmd_erase_ops(struct spi_f
  46. ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
  47. if (ret < 0) {
  48. debug("SF: erase failed\n");
  49. - break;
  50. + goto done;
  51. }
  52. offset += erase_size;
  53. len -= erase_size;
  54. }
  55. +done:
  56. + spi_release_bus(flash->spi);
  57. +
  58. return ret;
  59. }
  60. @@ -208,6 +209,12 @@ int spi_flash_cmd_write_ops(struct spi_f
  61. u8 cmd[4];
  62. int ret = -1;
  63. + ret = spi_claim_bus(flash->spi);
  64. + if (ret) {
  65. + debug("SF: unable to claim SPI bus\n");
  66. + return ret;
  67. + }
  68. +
  69. page_size = flash->page_size;
  70. cmd[0] = CMD_PAGE_PROGRAM;
  71. @@ -215,7 +222,7 @@ int spi_flash_cmd_write_ops(struct spi_f
  72. #ifdef CONFIG_SPI_FLASH_BAR
  73. ret = spi_flash_bank(flash, offset);
  74. if (ret < 0)
  75. - return ret;
  76. + goto done;
  77. #endif
  78. byte_addr = offset % page_size;
  79. chunk_len = min(len - actual, page_size - byte_addr);
  80. @@ -232,12 +239,15 @@ int spi_flash_cmd_write_ops(struct spi_f
  81. buf + actual, chunk_len);
  82. if (ret < 0) {
  83. debug("SF: write failed\n");
  84. - break;
  85. + goto done;
  86. }
  87. offset += chunk_len;
  88. }
  89. +done:
  90. + spi_release_bus(flash->spi);
  91. +
  92. return ret;
  93. }
  94. @@ -247,20 +257,12 @@ int spi_flash_read_common(struct spi_fla
  95. struct spi_slave *spi = flash->spi;
  96. int ret;
  97. - ret = spi_claim_bus(flash->spi);
  98. - if (ret) {
  99. - debug("SF: unable to claim SPI bus\n");
  100. - return ret;
  101. - }
  102. -
  103. ret = spi_flash_cmd_read(spi, cmd, cmd_len, data, data_len);
  104. if (ret < 0) {
  105. debug("SF: read cmd failed\n");
  106. return ret;
  107. }
  108. - spi_release_bus(spi);
  109. -
  110. return ret;
  111. }
  112. @@ -271,6 +273,12 @@ int spi_flash_cmd_read_ops(struct spi_fl
  113. u32 remain_len, read_len;
  114. int ret = -1;
  115. + ret = spi_claim_bus(flash->spi);
  116. + if (ret) {
  117. + debug("SF: unable to claim SPI bus\n");
  118. + return ret;
  119. + }
  120. +
  121. /* Handle memory-mapped SPI */
  122. if (flash->memory_map) {
  123. spi_xfer(flash->spi, 0, NULL, NULL, SPI_XFER_MMAP);
  124. @@ -289,7 +297,7 @@ int spi_flash_cmd_read_ops(struct spi_fl
  125. ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
  126. if (ret) {
  127. debug("SF: fail to set bank%d\n", bank_sel);
  128. - return ret;
  129. + goto done;
  130. }
  131. #endif
  132. remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1)) - offset;
  133. @@ -304,7 +312,7 @@ int spi_flash_cmd_read_ops(struct spi_fl
  134. data, read_len);
  135. if (ret < 0) {
  136. debug("SF: read failed\n");
  137. - break;
  138. + goto done;
  139. }
  140. offset += read_len;
  141. @@ -312,6 +320,9 @@ int spi_flash_cmd_read_ops(struct spi_fl
  142. data += read_len;
  143. }
  144. +done:
  145. + spi_release_bus(flash->spi);
  146. +
  147. return ret;
  148. }