7f90cf946a4d444fd01d6da07cb64a65d8e3f5b9
[openwrt/staging/xback.git] /
1 From 1186af457cc186c5ed01708da71b1ffbdf0a2638 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Tue, 20 Nov 2018 09:55:45 +0100
4 Subject: [PATCH] mtd: keep original flags for every struct mtd_info
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 When allocating a new partition mtd subsystem runs internal tests in the
10 allocate_partition(). They may result in modifying specified flags (e.g.
11 dropping some /features/ like write access).
12
13 Those constraints don't have to be necessary true for subpartitions. It
14 may happen parent partition isn't block aligned (effectively disabling
15 write access) while subpartition may fit blocks nicely. In such case all
16 checks should be run again (starting with original flags value).
17
18 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
19 Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
20 ---
21 drivers/mtd/mtdcore.c | 2 ++
22 drivers/mtd/mtdpart.c | 3 ++-
23 include/linux/mtd/mtd.h | 1 +
24 3 files changed, 5 insertions(+), 1 deletion(-)
25
26 --- a/drivers/mtd/mtdcore.c
27 +++ b/drivers/mtd/mtdcore.c
28 @@ -650,6 +650,8 @@ static void mtd_set_dev_defaults(struct
29 } else {
30 pr_debug("mtd device won't show a device symlink in sysfs\n");
31 }
32 +
33 + mtd->orig_flags = mtd->flags;
34 }
35
36 /**
37 --- a/drivers/mtd/mtdpart.c
38 +++ b/drivers/mtd/mtdpart.c
39 @@ -394,7 +394,8 @@ static struct mtd_part *allocate_partiti
40
41 /* set up the MTD object for this partition */
42 slave->mtd.type = parent->type;
43 - slave->mtd.flags = parent->flags & ~part->mask_flags;
44 + slave->mtd.flags = parent->orig_flags & ~part->mask_flags;
45 + slave->mtd.orig_flags = slave->mtd.flags;
46 slave->mtd.size = part->size;
47 slave->mtd.writesize = parent->writesize;
48 slave->mtd.writebufsize = parent->writebufsize;
49 --- a/include/linux/mtd/mtd.h
50 +++ b/include/linux/mtd/mtd.h
51 @@ -218,6 +218,7 @@ struct mtd_debug_info {
52 struct mtd_info {
53 u_char type;
54 uint32_t flags;
55 + uint32_t orig_flags; /* Flags as before running mtd checks */
56 uint64_t size; // Total size of the MTD
57
58 /* "Major" erase size for the device. Naïve users may take this