Commit 82e214f6 authored by Vincent Whitchurch's avatar Vincent Whitchurch Committed by Miquel Raynal
Browse files

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: default avatarVincent Whitchurch <vincent.whitchurch@axis.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220412135302.1682890-2-vincent.whitchurch@axis.com
parent 9547c4e7
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -557,9 +557,10 @@ static int mtd_nvmem_add(struct mtd_info *mtd)

int add_mtd_device(struct mtd_info *mtd)
{
	struct device_node *np = mtd_get_of_node(mtd);
	struct mtd_info *master = mtd_get_master(mtd);
	struct mtd_notifier *not;
	int i, error;
	int i, error, ofidx;

	/*
	 * May occur, for instance, on buggy drivers which call
@@ -598,6 +599,12 @@ int add_mtd_device(struct mtd_info *mtd)

	mutex_lock(&mtd_table_mutex);

	ofidx = -1;
	if (np)
		ofidx = of_alias_get_id(np, "mtd");
	if (ofidx >= 0)
		i = idr_alloc(&mtd_idr, mtd, ofidx, ofidx + 1, GFP_KERNEL);
	else
		i = idr_alloc(&mtd_idr, mtd, 0, 0, GFP_KERNEL);
	if (i < 0) {
		error = i;