Skip to content

Commit 82e214f

Browse files
vwaxmiquelraynal
authored andcommitted
mtd: core: Check devicetree alias for index
Allow the MTD index to be specified via a devicetree alias, so that the number does not just depend on probe order. This is useful to allow pseudo-devices like phram to be optionally used on systems, without having this affect the numbering of the real hardware MTD devices. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220412135302.1682890-2-vincent.whitchurch@axis.com
1 parent 9547c4e commit 82e214f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/mtd/mtdcore.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,10 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
557557

558558
int add_mtd_device(struct mtd_info *mtd)
559559
{
560+
struct device_node *np = mtd_get_of_node(mtd);
560561
struct mtd_info *master = mtd_get_master(mtd);
561562
struct mtd_notifier *not;
562-
int i, error;
563+
int i, error, ofidx;
563564

564565
/*
565566
* May occur, for instance, on buggy drivers which call
@@ -598,7 +599,13 @@ int add_mtd_device(struct mtd_info *mtd)
598599

599600
mutex_lock(&mtd_table_mutex);
600601

601-
i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
602+
ofidx = -1;
603+
if (np)
604+
ofidx = of_alias_get_id(np, "mtd");
605+
if (ofidx >= 0)
606+
i = idr_alloc(&mtd_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
607+
else
608+
i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
602609
if (i < 0) {
603610
error = i;
604611
goto fail_locked;

0 commit comments

Comments
 (0)