063-v4.11-0002-mtd-introduce-function-max_bad_blocks.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From 6080ef6e7c0a0592cbcca11200d879faf65e27d4 Mon Sep 17 00:00:00 2001
  2. From: Jeff Westfahl <jeff.westfahl@ni.com>
  3. Date: Tue, 10 Jan 2017 13:30:17 -0600
  4. Subject: [PATCH] mtd: introduce function max_bad_blocks
  5. If implemented, 'max_bad_blocks' returns the maximum number of bad
  6. blocks to reserve for a MTD. An implementation for NAND is coming soon.
  7. Signed-off-by: Jeff Westfahl <jeff.westfahl@ni.com>
  8. Signed-off-by: Zach Brown <zach.brown@ni.com>
  9. Acked-by: Boris Brezillon <boris.brezillon@free-electron.com>
  10. Acked-by: Brian Norris <computersforpeace@gmail.com>
  11. Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  12. ---
  13. drivers/mtd/mtdpart.c | 10 ++++++++++
  14. include/linux/mtd/mtd.h | 13 +++++++++++++
  15. 2 files changed, 23 insertions(+)
  16. --- a/drivers/mtd/mtdpart.c
  17. +++ b/drivers/mtd/mtdpart.c
  18. @@ -349,6 +349,14 @@ static const struct mtd_ooblayout_ops pa
  19. .free = part_ooblayout_free,
  20. };
  21. +static int part_max_bad_blocks(struct mtd_info *mtd, loff_t ofs, size_t len)
  22. +{
  23. + struct mtd_part *part = mtd_to_part(mtd);
  24. +
  25. + return part->master->_max_bad_blocks(part->master,
  26. + ofs + part->offset, len);
  27. +}
  28. +
  29. static inline void free_partition(struct mtd_part *p)
  30. {
  31. kfree(p->mtd.name);
  32. @@ -475,6 +483,8 @@ static struct mtd_part *allocate_partiti
  33. slave->mtd._block_isbad = part_block_isbad;
  34. if (master->_block_markbad)
  35. slave->mtd._block_markbad = part_block_markbad;
  36. + if (master->_max_bad_blocks)
  37. + slave->mtd._max_bad_blocks = part_max_bad_blocks;
  38. if (master->_get_device)
  39. slave->mtd._get_device = part_get_device;
  40. --- a/include/linux/mtd/mtd.h
  41. +++ b/include/linux/mtd/mtd.h
  42. @@ -322,6 +322,7 @@ struct mtd_info {
  43. int (*_block_isreserved) (struct mtd_info *mtd, loff_t ofs);
  44. int (*_block_isbad) (struct mtd_info *mtd, loff_t ofs);
  45. int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs);
  46. + int (*_max_bad_blocks) (struct mtd_info *mtd, loff_t ofs, size_t len);
  47. int (*_suspend) (struct mtd_info *mtd);
  48. void (*_resume) (struct mtd_info *mtd);
  49. void (*_reboot) (struct mtd_info *mtd);
  50. @@ -397,6 +398,18 @@ static inline int mtd_oobavail(struct mt
  51. return ops->mode == MTD_OPS_AUTO_OOB ? mtd->oobavail : mtd->oobsize;
  52. }
  53. +static inline int mtd_max_bad_blocks(struct mtd_info *mtd,
  54. + loff_t ofs, size_t len)
  55. +{
  56. + if (!mtd->_max_bad_blocks)
  57. + return -ENOTSUPP;
  58. +
  59. + if (mtd->size < (len + ofs) || ofs < 0)
  60. + return -EINVAL;
  61. +
  62. + return mtd->_max_bad_blocks(mtd, ofs, len);
  63. +}
  64. +
  65. int mtd_wunit_to_pairing_info(struct mtd_info *mtd, int wunit,
  66. struct mtd_pairing_info *info);
  67. int mtd_pairing_info_to_wunit(struct mtd_info *mtd,