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