From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Daniel Golle <daniel@makrotopia.org>
Cc: linux-mtd@lists.infradead.org,
Vignesh Raghavendra <vigneshr@ti.com>,
Richard Weinberger <richard@nod.at>,
David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH v3] mtd: super: don't rely on mtdblock device minor
Date: Mon, 10 May 2021 12:18:37 +0200 [thread overview]
Message-ID: <20210510121837.14274d4f@xps13> (raw)
In-Reply-To: <YHRj5MUb5MGdPQqw@makrotopia.org>
Hi Daniel,
Daniel Golle <daniel@makrotopia.org> wrote on Mon, 12 Apr 2021 16:14:44
+0100:
> For blktrans devices with partitions (ie. part_bits != 0) the
> assumption that the minor number of the mtdblock device matches
> the mtdnum doesn't hold true.
> Properly resolve mtd device from blktrans layer instead.
Unfortunately I cannot apply your patch anymore, would you mind
rebasing it on top of v5.13-rc1?
Thanks,
Miquèl
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> v3: fix typo in patch description
> v2: remove BUG() calls as requested by Miquel Raynal
>
> drivers/mtd/mtdsuper.c | 31 ++++++++++++++++++++++++-------
> 1 file changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
> index c3e2098372f2e..d3af80a7ce86e 100644
> --- a/drivers/mtd/mtdsuper.c
> +++ b/drivers/mtd/mtdsuper.c
> @@ -9,6 +9,7 @@
> */
>
> #include <linux/mtd/super.h>
> +#include <linux/mtd/blktrans.h>
> #include <linux/namei.h>
> #include <linux/export.h>
> #include <linux/ctype.h>
> @@ -121,7 +122,8 @@ int get_tree_mtd(struct fs_context *fc,
> {
> #ifdef CONFIG_BLOCK
> struct block_device *bdev;
> - int ret, major;
> + struct mtd_blktrans_dev *blktrans_dev;
> + int ret, major, part_bits;
> #endif
> int mtdnr;
>
> @@ -169,21 +171,36 @@ int get_tree_mtd(struct fs_context *fc,
> /* try the old way - the hack where we allowed users to mount
> * /dev/mtdblock$(n) but didn't actually _use_ the blockdev
> */
> - bdev = lookup_bdev(fc->source);
> + bdev = blkdev_get_by_path(fc->source, FMODE_READ, NULL);
> if (IS_ERR(bdev)) {
> ret = PTR_ERR(bdev);
> errorf(fc, "MTD: Couldn't look up '%s': %d", fc->source, ret);
> return ret;
> }
> - pr_debug("MTDSB: lookup_bdev() returned 0\n");
> + pr_debug("MTDSB: blkdev_get_by_path() returned 0\n");
>
> major = MAJOR(bdev->bd_dev);
> - mtdnr = MINOR(bdev->bd_dev);
> - bdput(bdev);
>
> - if (major == MTD_BLOCK_MAJOR)
> - return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
> + if (major == MTD_BLOCK_MAJOR) {
> + if (!bdev->bd_disk) {
> + blkdev_put(bdev, FMODE_READ);
> + return -EINVAL;
> + }
> +
> + blktrans_dev = (struct mtd_blktrans_dev *)(bdev->bd_disk->private_data);
> + if (!blktrans_dev || !blktrans_dev->tr) {
> + blkdev_put(bdev, FMODE_READ);
> + return -EINVAL;
> + }
> + mtdnr = blktrans_dev->devnum;
> + part_bits = blktrans_dev->tr->part_bits;
> + blkdev_put(bdev, FMODE_READ);
> + if (MINOR(bdev->bd_dev) != (mtdnr << part_bits))
> + return -EINVAL;
>
> + return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
> + }
> + blkdev_put(bdev, FMODE_READ);
> #endif /* CONFIG_BLOCK */
>
> if (!(fc->sb_flags & SB_SILENT))
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2021-05-10 10:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-07 21:55 [PATCH] mtd: super: don't reply on mtdblock device minor Daniel Golle
2021-04-08 6:15 ` Miquel Raynal
2021-04-08 20:42 ` [PATCH v2] " Daniel Golle
2021-04-12 15:14 ` [PATCH v3] mtd: super: don't rely " Daniel Golle
2021-05-10 10:18 ` Miquel Raynal [this message]
2021-05-10 22:20 ` Daniel Golle
2021-05-10 22:21 ` [PATCH v4] " Daniel Golle
2021-05-11 5:49 ` Christoph Hellwig
2021-05-11 7:57 ` Daniel Golle
2021-05-11 16:42 ` Christoph Hellwig
2021-05-11 20:17 ` Daniel Golle
2021-05-12 6:42 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210510121837.14274d4f@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=daniel@makrotopia.org \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox