040-0002-mtd-bcm47xxpart-don-t-fail-because-of-bit-flips.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From 36bcc0c9c2bc8f56569cd735ba531a51358d7c2b Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Sun, 6 Dec 2015 11:31:38 +0100
  4. Subject: [PATCH] mtd: bcm47xxpart: don't fail because of bit-flips
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Bit-flip errors may occur on NAND flashes and are harmless. Handle them
  9. gracefully as read content is still reliable and can be parsed.
  10. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  11. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  12. ---
  13. drivers/mtd/bcm47xxpart.c | 38 ++++++++++++++++++++++----------------
  14. 1 file changed, 22 insertions(+), 16 deletions(-)
  15. --- a/drivers/mtd/bcm47xxpart.c
  16. +++ b/drivers/mtd/bcm47xxpart.c
  17. @@ -66,11 +66,13 @@ static const char *bcm47xxpart_trx_data_
  18. {
  19. uint32_t buf;
  20. size_t bytes_read;
  21. + int err;
  22. - if (mtd_read(master, offset, sizeof(buf), &bytes_read,
  23. - (uint8_t *)&buf) < 0) {
  24. - pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
  25. - offset);
  26. + err = mtd_read(master, offset, sizeof(buf), &bytes_read,
  27. + (uint8_t *)&buf);
  28. + if (err && !mtd_is_bitflip(err)) {
  29. + pr_err("mtd_read error while parsing (offset: 0x%X): %d\n",
  30. + offset, err);
  31. goto out_default;
  32. }
  33. @@ -95,6 +97,7 @@ static int bcm47xxpart_parse(struct mtd_
  34. int trx_part = -1;
  35. int last_trx_part = -1;
  36. int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
  37. + int err;
  38. /*
  39. * Some really old flashes (like AT45DB*) had smaller erasesize-s, but
  40. @@ -128,10 +131,11 @@ static int bcm47xxpart_parse(struct mtd_
  41. }
  42. /* Read beginning of the block */
  43. - if (mtd_read(master, offset, BCM47XXPART_BYTES_TO_READ,
  44. - &bytes_read, (uint8_t *)buf) < 0) {
  45. - pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
  46. - offset);
  47. + err = mtd_read(master, offset, BCM47XXPART_BYTES_TO_READ,
  48. + &bytes_read, (uint8_t *)buf);
  49. + if (err && !mtd_is_bitflip(err)) {
  50. + pr_err("mtd_read error while parsing (offset: 0x%X): %d\n",
  51. + offset, err);
  52. continue;
  53. }
  54. @@ -254,10 +258,11 @@ static int bcm47xxpart_parse(struct mtd_
  55. }
  56. /* Read middle of the block */
  57. - if (mtd_read(master, offset + 0x8000, 0x4,
  58. - &bytes_read, (uint8_t *)buf) < 0) {
  59. - pr_err("mtd_read error while parsing (offset: 0x%X)!\n",
  60. - offset);
  61. + err = mtd_read(master, offset + 0x8000, 0x4, &bytes_read,
  62. + (uint8_t *)buf);
  63. + if (err && !mtd_is_bitflip(err)) {
  64. + pr_err("mtd_read error while parsing (offset: 0x%X): %d\n",
  65. + offset, err);
  66. continue;
  67. }
  68. @@ -277,10 +282,11 @@ static int bcm47xxpart_parse(struct mtd_
  69. }
  70. offset = master->size - possible_nvram_sizes[i];
  71. - if (mtd_read(master, offset, 0x4, &bytes_read,
  72. - (uint8_t *)buf) < 0) {
  73. - pr_err("mtd_read error while reading at offset 0x%X!\n",
  74. - offset);
  75. + err = mtd_read(master, offset, 0x4, &bytes_read,
  76. + (uint8_t *)buf);
  77. + if (err && !mtd_is_bitflip(err)) {
  78. + pr_err("mtd_read error while reading (offset 0x%X): %d\n",
  79. + offset, err);
  80. continue;
  81. }