kernel: don't switch allocate_partition to use mtd_roundup_to_eb
[openwrt/openwrt.git] / target / linux / generic / patches-4.9 / 404-mtd-add-more-helper-functions.patch
1 --- a/drivers/mtd/mtdpart.c
2 +++ b/drivers/mtd/mtdpart.c
3 @@ -717,6 +717,17 @@ run_parsers_by_type(struct mtd_part *sla
4 return nr_parts;
5 }
6
7 +static inline unsigned long
8 +mtd_pad_erasesize(struct mtd_info *mtd, int offset, int len)
9 +{
10 + unsigned long mask = mtd->erasesize - 1;
11 +
12 + len += offset & mask;
13 + len = (len + mask) & ~mask;
14 + len -= offset & mask;
15 + return len;
16 +}
17 +
18 #ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
19 #define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
20 #else
21 @@ -1055,6 +1066,24 @@ int mtd_is_partition(const struct mtd_in
22 }
23 EXPORT_SYMBOL_GPL(mtd_is_partition);
24
25 +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd)
26 +{
27 + if (!mtd_is_partition(mtd))
28 + return (struct mtd_info *)mtd;
29 +
30 + return mtd_to_part(mtd)->master;
31 +}
32 +EXPORT_SYMBOL_GPL(mtdpart_get_master);
33 +
34 +uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
35 +{
36 + if (!mtd_is_partition(mtd))
37 + return 0;
38 +
39 + return mtd_to_part(mtd)->offset;
40 +}
41 +EXPORT_SYMBOL_GPL(mtdpart_get_offset);
42 +
43 /* Returns the size of the entire flash chip */
44 uint64_t mtd_get_device_size(const struct mtd_info *mtd)
45 {
46 --- a/include/linux/mtd/partitions.h
47 +++ b/include/linux/mtd/partitions.h
48 @@ -106,6 +106,8 @@ int mtd_is_partition(const struct mtd_in
49 int mtd_add_partition(struct mtd_info *master, const char *name,
50 long long offset, long long length);
51 int mtd_del_partition(struct mtd_info *master, int partno);
52 +struct mtd_info *mtdpart_get_master(const struct mtd_info *mtd);
53 +uint64_t mtdpart_get_offset(const struct mtd_info *mtd);
54 uint64_t mtd_get_device_size(const struct mtd_info *mtd);
55 extern void __weak arch_split_mtd_part(struct mtd_info *master,
56 const char *name, int offset, int size);
57 --- a/include/linux/mtd/mtd.h
58 +++ b/include/linux/mtd/mtd.h
59 @@ -472,6 +472,24 @@ static inline uint32_t mtd_mod_by_eb(uin
60 return do_div(sz, mtd->erasesize);
61 }
62
63 +static inline uint64_t mtd_roundup_to_eb(uint64_t sz, struct mtd_info *mtd)
64 +{
65 + if (mtd_mod_by_eb(sz, mtd) == 0)
66 + return sz;
67 +
68 + /* Round up to next erase block */
69 + return (mtd_div_by_eb(sz, mtd) + 1) * mtd->erasesize;
70 +}
71 +
72 +static inline uint64_t mtd_rounddown_to_eb(uint64_t sz, struct mtd_info *mtd)
73 +{
74 + if (mtd_mod_by_eb(sz, mtd) == 0)
75 + return sz;
76 +
77 + /* Round down to the start of the current erase block */
78 + return (mtd_div_by_eb(sz, mtd)) * mtd->erasesize;
79 +}
80 +
81 static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
82 {
83 if (mtd->writesize_shift)