ath25: switch default kernel to 5.15
[openwrt/openwrt.git] / target / linux / generic / hack-5.10 / 401-mtd-super-don-t-reply-on-mtdblock-device-minor.patch
1 From f9760b158f610b1792a222cc924073724c061bfb Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Wed, 7 Apr 2021 22:37:57 +0100
4 Subject: [PATCH 1/2] mtd: super: don't reply on mtdblock device minor
5 To: linux-mtd@lists.infradead.org
6 Cc: Vignesh Raghavendra <vigneshr@ti.com>,
7 Richard Weinberger <richard@nod.at>,
8 Miquel Raynal <miquel.raynal@bootlin.com>,
9 David Woodhouse <dwmw2@infradead.org>
10
11 For blktrans devices with partitions (ie. part_bits != 0) the
12 assumption that the minor number of the mtdblock device matches
13 the mtdnum doesn't hold true.
14 Properly resolve mtd device from blktrans layer instead.
15
16 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
17 ---
18 drivers/mtd/mtdsuper.c | 33 ++++++++++++++++++++++++++-------
19 1 file changed, 26 insertions(+), 7 deletions(-)
20
21 --- a/drivers/mtd/mtdsuper.c
22 +++ b/drivers/mtd/mtdsuper.c
23 @@ -9,6 +9,7 @@
24 */
25
26 #include <linux/mtd/super.h>
27 +#include <linux/mtd/blktrans.h>
28 #include <linux/namei.h>
29 #include <linux/export.h>
30 #include <linux/ctype.h>
31 @@ -121,7 +122,8 @@ int get_tree_mtd(struct fs_context *fc,
32 {
33 #ifdef CONFIG_BLOCK
34 struct block_device *bdev;
35 - int ret, major;
36 + struct mtd_blktrans_dev *blktrans_dev;
37 + int ret, major, part_bits;
38 #endif
39 int mtdnr;
40
41 @@ -169,21 +171,38 @@ int get_tree_mtd(struct fs_context *fc,
42 /* try the old way - the hack where we allowed users to mount
43 * /dev/mtdblock$(n) but didn't actually _use_ the blockdev
44 */
45 - bdev = lookup_bdev(fc->source);
46 + bdev = blkdev_get_by_path(fc->source, FMODE_READ, NULL);
47 if (IS_ERR(bdev)) {
48 ret = PTR_ERR(bdev);
49 errorf(fc, "MTD: Couldn't look up '%s': %d", fc->source, ret);
50 return ret;
51 }
52 - pr_debug("MTDSB: lookup_bdev() returned 0\n");
53 + pr_debug("MTDSB: blkdev_get_by_path() returned 0\n");
54
55 major = MAJOR(bdev->bd_dev);
56 - mtdnr = MINOR(bdev->bd_dev);
57 - bdput(bdev);
58
59 - if (major == MTD_BLOCK_MAJOR)
60 - return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
61 + if (major == MTD_BLOCK_MAJOR) {
62 + if (!bdev->bd_disk) {
63 + blkdev_put(bdev, FMODE_READ);
64 + BUG();
65 + return -EINVAL;
66 + }
67 +
68 + blktrans_dev = (struct mtd_blktrans_dev *)(bdev->bd_disk->private_data);
69 + if (!blktrans_dev || !blktrans_dev->tr) {
70 + blkdev_put(bdev, FMODE_READ);
71 + BUG();
72 + return -EINVAL;
73 + }
74 + mtdnr = blktrans_dev->devnum;
75 + part_bits = blktrans_dev->tr->part_bits;
76 + blkdev_put(bdev, FMODE_READ);
77 + if (MINOR(bdev->bd_dev) != (mtdnr << part_bits))
78 + return -EINVAL;
79
80 + return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
81 + }
82 + blkdev_put(bdev, FMODE_READ);
83 #endif /* CONFIG_BLOCK */
84
85 if (!(fc->sb_flags & SB_SILENT))