// SPDX-License-Identifier: GPL-2.0+
/*
 * Simple MTD partitioning layer
 *
 * Copyright © 2000 Nicolas Pitre <nico@fluxnic.net>
 * Copyright © 2002 Thomas Gleixner <gleixner@linutronix.de>
 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
 *
 */

#ifndef __UBOOT__
#include <log.h>
#include <dm/devres.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/kmod.h>
#endif

#include <malloc.h>
#include <linux/bug.h>
#include <linux/errno.h>
#include <linux/compat.h>
#include <ubi_uboot.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/err.h>
#include <linux/sizes.h>

#include "mtdcore.h"

#ifndef __UBOOT__
static DEFINE_MUTEX(mtd_partitions_mutex);
#else
DEFINE_MUTEX(mtd_partitions_mutex);
#endif

#ifdef __UBOOT__
/* from mm/util.c */

/**
 * kstrdup - allocate space for and copy an existing string
 * @s: the string to duplicate
 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
 */
char *kstrdup(const char *s, gfp_t gfp)
{
	size_t len;
	char *buf;

	if (!s)
		return NULL;

	len = strlen(s) + 1;
	buf = kmalloc(len, gfp);
	if (buf)
		memcpy(buf, s, len);
	return buf;
}
#endif

#define MTD_SIZE_REMAINING		(~0LLU)
#define MTD_OFFSET_NOT_SPECIFIED	(~0LLU)

bool mtd_partitions_used(struct mtd_info *master)
{
	struct mtd_info *slave;

	list_for_each_entry(slave, &master->partitions, node) {
		if (slave->usecount)
			return true;
	}

	return false;
}

/**
 * mtd_parse_partition - Parse @mtdparts partition definition, fill @partition
 *                       with it and update the @mtdparts string pointer.
 *
 * The partition name is allocated and must be freed by the caller.
 *
 * This function is widely inspired from part_parse (mtdparts.c).
 *
 * @mtdparts: String describing the partition with mtdparts command syntax
 * @partition: MTD partition structure to fill
 *
 * Return: 0 on success, an error otherwise.
 */
static int mtd_parse_partition(const char **_mtdparts,
			       struct mtd_partition *partition)
{
	const char *mtdparts = *_mtdparts;
	const char *name = NULL;
	int name_len;
	char *buf;

	/* Ensure the partition structure is empty */
	memset(partition, 0, sizeof(struct mtd_partition));

	/* Fetch the partition size */
	if (*mtdparts == '-') {
		/* Assign all remaining space to this partition */
		partition->size = MTD_SIZE_REMAINING;
		mtdparts++;
	} else {
		partition->size = ustrtoull(mtdparts, (char **)&mtdparts, 0);
		if (partition->size < SZ_4K) {
			printf("Minimum partition size 4kiB, %lldB requested\n",
			       partition->size);
			return -EINVAL;
		}
	}

	/* Check for the offset */
	partition->offset = MTD_OFFSET_NOT_SPECIFIED;
	if (*mtdparts == '@') {
		mtdparts++;
		partition->offset = ustrtoull(mtdparts, (char **)&mtdparts, 0);
	}

	/* Now look for the name */
	if (*mtdparts == '(') {
		name = ++mtdparts;
		mtdparts = strchr(name, ')');
		if (!mtdparts) {
			printf("No closing ')' found in partition name\n");
			return -EINVAL;
		}
		name_len = mtdparts - name + 1;
		if ((name_len - 1) == 0) {
			printf("Empty partition name\n");
			return -EINVAL;
		}
		mtdparts++;
	} else {
		/* Name will be of the form size@offset */
		name_len = 22;
	}

	/* Check if the partition is read-only */
	if (strncmp(mtdparts, "ro", 2) == 0) {
		partition->mask_flags |= MTD_WRITEABLE;
		mtdparts += 2;
	}

	/* Check for a potential next partition definition */
	if (*mtdparts == ',') {
		if (partition->size == MTD_SIZE_REMAINING) {
			printf("No partitions allowed after a fill-up\n");
			return -EINVAL;
		}
		++mtdparts;
	} else if ((*mtdparts == ';') || (*mtdparts == '\0')) {
		/* NOP */
	} else {
		printf("Unexpected character '%c' in mtdparts\n", *mtdparts);
		return -EINVAL;
	}

	/*
	 * Allocate a buffer for the name and either copy the provided name or
	 * auto-generate it with the form 'size@offset'.
	 */
	buf = malloc(name_len);
	if (!buf)
		return -ENOMEM;

	if (name)
		strncpy(buf, name, name_len - 1);
	else
		snprintf(buf, name_len, "0x%08llx@0x%08llx",
			 partition->size, partition->offset);

	buf[name_len - 1] = '\0';
	partition->name = buf;

	*_mtdparts = mtdparts;

	return 0;
}

/**
 * mtd_parse_partitions - Create a partition array from an mtdparts definition
 *
 * Stateless function that takes a @parent MTD device, a string @_mtdparts
 * describing the partitions (with the "mtdparts" command syntax) and creates
 * the corresponding MTD partition structure array @_parts. Both the name and
 * the structure partition itself must be freed freed, the caller may use
 * @mtd_free_parsed_partitions() for this purpose.
 *
 * @parent: MTD device which contains the partitions
 * @_mtdparts: Pointer to a string describing the partitions with "mtdparts"
 *             command syntax.
 * @_parts: Allocated array containing the partitions, must be freed by the
 *          caller.
 * @_nparts: Size of @_parts array.
 *
 * Return: 0 on success, an error otherwise.
 */
int mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
			 struct mtd_partition **_parts, int *_nparts)
{
	struct mtd_partition partition = {}, *parts;
	const char *mtdparts = *_mtdparts;
	uint64_t cur_off = 0, cur_sz = 0;
	int nparts = 0;
	int ret, idx;
	u64 sz;

	/* First, iterate over the partitions until we know their number */
	while (mtdparts[0] != '\0' && mtdparts[0] != ';') {
		ret = mtd_parse_partition(&mtdparts, &partition);
		if (ret)
			return ret;

		free((char *)partition.name);
		nparts++;
	}

	/* Allocate an array of partitions to give back to the caller */
	parts = malloc(sizeof(*parts) * nparts);
	if (!parts) {
		printf("Not enough space to save partitions meta-data\n");
		return -ENOMEM;
	}

	/* Iterate again over each partition to save the data in our array */
	for (idx = 0; idx < nparts; idx++) {
		ret = mtd_parse_partition(_mtdparts, &parts[idx]);
		if (ret)
			return ret;

		if (parts[idx].size == MTD_SIZE_REMAINING)
			parts[idx].size = parent->size - cur_sz;
		cur_sz += parts[idx].size;

		sz = parts[idx].size;
		if (sz < parent->writesize || do_div(sz, parent->writesize)) {
			printf("Partition size must be a multiple of %d\n",
			       parent->writesize);
			return -EINVAL;
		}

		if (parts[idx].offset == MTD_OFFSET_NOT_SPECIFIED)
			parts[idx].offset = cur_off;
		cur_off += parts[idx].size;

		parts[idx].ecclayout = parent->ecclayout;
	}

	/* Offset by one mtdparts to point to the next device if any */
	if (*_mtdparts[0] == ';')
		(*_mtdparts)++;

	*_parts = parts;
	*_nparts = nparts;

	return 0;
}

/**
 * mtd_free_parsed_partitions - Free dynamically allocated partitions
 *
 * Each successful call to @mtd_parse_partitions must be followed by a call to
 * @mtd_free_parsed_partitions to free any allocated array during the parsing
 * process.
 *
 * @parts: Array containing the partitions that will be freed.
 * @nparts: Size of @parts array.
 */
void mtd_free_parsed_partitions(struct mtd_partition *parts,
				unsigned int nparts)
{
	int i;

	for (i = 0; i < nparts; i++)
		free((char *)parts[i].name);

	free(parts);
}

/*
 * MTD methods which simply translate the effective address and pass through
 * to the _real_ device.
 */

static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
		size_t *retlen, u_char *buf)
{
	struct mtd_ecc_stats stats;
	int res;

	stats = mtd->parent->ecc_stats;
	res = mtd->parent->_read(mtd->parent, from + mtd->offset, len,
				 retlen, buf);
	if (unlikely(mtd_is_eccerr(res)))
		mtd->ecc_stats.failed +=
			mtd->parent->ecc_stats.failed - stats.failed;
	else
		mtd->ecc_stats.corrected +=
			mtd->parent->ecc_stats.corrected - stats.corrected;
	return res;
}

#ifndef __UBOOT__
static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
		size_t *retlen, void **virt, resource_size_t *phys)
{
	return mtd->parent->_point(mtd->parent, from + mtd->offset, len,
				   retlen, virt, phys);
}

static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
{
	return mtd->parent->_unpoint(mtd->parent, from + mtd->offset, len);
}
#endif

static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
					    unsigned long len,
					    unsigned long offset,
					    unsigned long flags)
{
	offset += mtd->offset;
	return mtd->parent->_get_unmapped_area(mtd->parent, len, offset, flags);
}

static int part_read_oob(struct mtd_info *mtd, loff_t from,
		struct mtd_oob_ops *ops)
{
	int res;

	if (from >= mtd->size)
		return -EINVAL;
	if (ops->datbuf && from + ops->len > mtd->size)
		return -EINVAL;

	/*
	 * If OOB is also requested, make sure that we do not read past the end
	 * of this partition.
	 */
	if (ops->oobbuf) {
		size_t len, pages;

		if (ops->mode == MTD_OPS_AUTO_OOB)
			len = mtd->oobavail;
		else
			len = mtd->oobsize;
		pages = mtd_div_by_ws(mtd->size, mtd);
		pages -= mtd_div_by_ws(from, mtd);
		if (ops->ooboffs + ops->ooblen > pages * len)
			return -EINVAL;
	}

	res = mtd->parent->_read_oob(mtd->parent, from + mtd->offset, ops);
	if (unlikely(res)) {
		if (mtd_is_bitflip(res))
			mtd->ecc_stats.corrected++;
		if (mtd_is_eccerr(res))
			mtd->ecc_stats.failed++;
	}
	return res;
}

static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
		size_t len, size_t *retlen, u_char *buf)
{
	return mtd->parent->_read_user_prot_reg(mtd->parent, from, len,
						retlen, buf);
}

static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
				   size_t *retlen, struct otp_info *buf)
{
	return mtd->parent->_get_user_prot_info(mtd->parent, len, retlen,
						buf);
}

static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
		size_t len, size_t *retlen, u_char *buf)
{
	return mtd->parent->_read_fact_prot_reg(mtd->parent, from, len,
						retlen, buf);
}

static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
				   size_t *retlen, struct otp_info *buf)
{
	return mtd->parent->_get_fact_prot_info(mtd->parent, len, retlen,
						buf);
}

static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
		size_t *retlen, const u_char *buf)
{
	return mtd->parent->_write(mtd->parent, to + mtd->offset, len,
				   retlen, buf);
}

static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
		size_t *retlen, const u_char *buf)
{
	return mtd->parent->_panic_write(mtd->parent, to + mtd->offset, len,
					 retlen, buf);
}

static int part_write_oob(struct mtd_info *mtd, loff_t to,
		struct mtd_oob_ops *ops)
{
	if (to >= mtd->size)
		return -EINVAL;
	if (ops->datbuf && to + ops->len > mtd->size)
		return -EINVAL;
	return mtd->parent->_write_oob(mtd->parent, to + mtd->offset, ops);
}

static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
		size_t len, size_t *retlen, u_char *buf)
{
	return mtd->parent->_write_user_prot_reg(mtd->parent, from, len,
						 retlen, buf);
}

static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
		size_t len)
{
	return mtd->parent->_lock_user_prot_reg(mtd->parent, from, len);
}

#ifndef __UBOOT__
static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
		unsigned long count, loff_t to, size_t *retlen)
{
	return mtd->parent->_writev(mtd->parent, vecs, count,
				    to + mtd->offset, retlen);
}
#endif

static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
{
	int ret;

	instr->addr += mtd->offset;

	ret = mtd->parent->_erase(mtd->parent, instr);
	if (ret && instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
		instr->fail_addr -= mtd->offset;

	instr->addr -= mtd->offset;

	return ret;
}

static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
	return mtd->parent->_lock(mtd->parent, ofs + mtd->offset, len);
}

static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
	return mtd->parent->_unlock(mtd->parent, ofs + mtd->offset, len);
}

static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
	return mtd->parent->_is_locked(mtd->parent, ofs + mtd->offset, len);
}

static void part_sync(struct mtd_info *mtd)
{
	mtd->parent->_sync(mtd->parent);
}

#ifndef __UBOOT__
static int part_suspend(struct mtd_info *mtd)
{
	return mtd->parent->_suspend(mtd->parent);
}

static void part_resume(struct mtd_info *mtd)
{
	mtd->parent->_resume(mtd->parent);
}
#endif

static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
{
	ofs += mtd->offset;
	return mtd->parent->_block_isreserved(mtd->parent, ofs);
}

static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
{
	ofs += mtd->offset;
	return mtd->parent->_block_isbad(mtd->parent, ofs);
}

static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
{
	int res;

	ofs += mtd->offset;
	res = mtd->parent->_block_markbad(mtd->parent, ofs);
	if (!res)
		mtd->ecc_stats.badblocks++;
	return res;
}

static inline void free_partition(struct mtd_info *p)
{
	kfree(p->name);
	kfree(p);
}

/*
 * This function unregisters and destroy all slave MTD objects which are
 * attached to the given master MTD object, recursively.
 */
static int do_del_mtd_partitions(struct mtd_info *master)
{
	struct mtd_info *slave, *next;
	int ret, err = 0;

	list_for_each_entry_safe(slave, next, &master->partitions, node) {
		if (mtd_has_partitions(slave))
			del_mtd_partitions(slave);

		debug("Deleting %s MTD partition\n", slave->name);
		ret = del_mtd_device(slave);
		if (ret < 0) {
			printf("Error when deleting partition \"%s\" (%d)\n",
			       slave->name, ret);
			err = ret;
			continue;
		}

		list_del(&slave->node);
		free_partition(slave);
	}

	return err;
}

int del_mtd_partitions(struct mtd_info *master)
{
	int ret;

	debug("Deleting MTD partitions on \"%s\":\n", master->name);

	mutex_lock(&mtd_partitions_mutex);
	ret = do_del_mtd_partitions(master);
	mutex_unlock(&mtd_partitions_mutex);

	return ret;
}

static struct mtd_info *allocate_partition(struct mtd_info *master,
					   const struct mtd_partition *part,
					   int partno, uint64_t cur_offset)
{
	struct mtd_info *slave;
	char *name;

	/* allocate the partition structure */
	slave = kzalloc(sizeof(*slave), GFP_KERNEL);
	name = kstrdup(part->name, GFP_KERNEL);
	if (!name || !slave) {
		printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
		       master->name);
		kfree(name);
		kfree(slave);
		return ERR_PTR(-ENOMEM);
	}

	/* set up the MTD object for this partition */
	slave->type = master->type;
	slave->flags = master->flags & ~part->mask_flags;
	slave->size = part->size;
	slave->writesize = master->writesize;
	slave->writebufsize = master->writebufsize;
	slave->oobsize = master->oobsize;
	slave->oobavail = master->oobavail;
	slave->subpage_sft = master->subpage_sft;

	slave->name = name;
	slave->owner = master->owner;
#ifndef __UBOOT__
	slave->backing_dev_info = master->backing_dev_info;

	/* NOTE:  we don't arrange MTDs as a tree; it'd be error-prone
	 * to have the same data be in two different partitions.
	 */
	slave->dev.parent = master->dev.parent;
#endif

	if (master->_read)
		slave->_read = part_read;
	if (master->_write)
		slave->_write = part_write;

	if (master->_panic_write)
		slave->_panic_write = part_panic_write;

#ifndef __UBOOT__
	if (master->_point && master->_unpoint) {
		slave->_point = part_point;
		slave->_unpoint = part_unpoint;
	}
#endif

	if (master->_get_unmapped_area)
		slave->_get_unmapped_area = part_get_unmapped_area;
	if (master->_read_oob)
		slave->_read_oob = part_read_oob;
	if (master->_write_oob)
		slave->_write_oob = part_write_oob;
	if (master->_read_user_prot_reg)
		slave->_read_user_prot_reg = part_read_user_prot_reg;
	if (master->_read_fact_prot_reg)
		slave->_read_fact_prot_reg = part_read_fact_prot_reg;
	if (master->_write_user_prot_reg)
		slave->_write_user_prot_reg = part_write_user_prot_reg;
	if (master->_lock_user_prot_reg)
		slave->_lock_user_prot_reg = part_lock_user_prot_reg;
	if (master->_get_user_prot_info)
		slave->_get_user_prot_info = part_get_user_prot_info;
	if (master->_get_fact_prot_info)
		slave->_get_fact_prot_info = part_get_fact_prot_info;
	if (master->_sync)
		slave->_sync = part_sync;
#ifndef __UBOOT__
	if (!partno && !master->dev.class && master->_suspend &&
	    master->_resume) {
		slave->_suspend = part_suspend;
		slave->_resume = part_resume;
	}
	if (master->_writev)
		slave->_writev = part_writev;
#endif
	if (master->_lock)
		slave->_lock = part_lock;
	if (master->_unlock)
		slave->_unlock = part_unlock;
	if (master->_is_locked)
		slave->_is_locked = part_is_locked;
	if (master->_block_isreserved)
		slave->_block_isreserved = part_block_isreserved;
	if (master->_block_isbad)
		slave->_block_isbad = part_block_isbad;
	if (master->_block_markbad)
		slave->_block_markbad = part_block_markbad;
	slave->_erase = part_erase;
	slave->parent = master;
	slave->offset = part->offset;
	INIT_LIST_HEAD(&slave->partitions);
	INIT_LIST_HEAD(&slave->node);

	if (slave->offset == MTDPART_OFS_APPEND)
		slave->offset = cur_offset;
	if (slave->offset == MTDPART_OFS_NXTBLK) {
		slave->offset = cur_offset;
		if (mtd_mod_by_eb(cur_offset, master) != 0) {
			/* Round up to next erasesize */
			slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
			debug("Moving partition %d: "
			       "0x%012llx -> 0x%012llx\n", partno,
			       (unsigned long long)cur_offset, (unsigned long long)slave->offset);
		}
	}
	if (slave->offset == MTDPART_OFS_RETAIN) {
		slave->offset = cur_offset;
		if (master->size - slave->offset >= slave->size) {
			slave->size = master->size - slave->offset
							- slave->size;
		} else {
			debug("mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
				part->name, master->size - slave->offset,
				slave->size);
			/* register to preserve ordering */
			goto out_register;
		}
	}
	if (slave->size == MTDPART_SIZ_FULL)
		slave->size = master->size - slave->offset;

	debug("0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset,
		(unsigned long long)(slave->offset + slave->size), slave->name);

	/* let's do some sanity checks */
	if (slave->offset >= master->size) {
		/* let's register it anyway to preserve ordering */
		slave->offset = 0;
		slave->size = 0;
		printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
			part->name);
		goto out_register;
	}
	if (slave->offset + slave->size > master->size) {
		slave->size = master->size - slave->offset;
		printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
		       part->name, master->name, slave->size);
	}
	if (master->numeraseregions > 1) {
		/* Deal with variable erase size stuff */
		int i, max = master->numeraseregions;
		u64 end = slave->offset + slave->size;
		struct mtd_erase_region_info *regions = master->eraseregions;

		/* Find the first erase regions which is part of this
		 * partition. */
		for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
			;
		/* The loop searched for the region _behind_ the first one */
		if (i > 0)
			i--;

		/* Pick biggest erasesize */
		for (; i < max && regions[i].offset < end; i++) {
			if (slave->erasesize < regions[i].erasesize)
				slave->erasesize = regions[i].erasesize;
		}
		WARN_ON(slave->erasesize == 0);
	} else {
		/* Single erase size */
		slave->erasesize = master->erasesize;
	}

	if ((slave->flags & MTD_WRITEABLE) &&
	    mtd_mod_by_eb(slave->offset, slave)) {
		/* Doesn't start on a boundary of major erase size */
		/* FIXME: Let it be writable if it is on a boundary of
		 * _minor_ erase size though */
		slave->flags &= ~MTD_WRITEABLE;
		printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
			part->name);
	}
	if ((slave->flags & MTD_WRITEABLE) &&
	    mtd_mod_by_eb(slave->size, slave)) {
		slave->flags &= ~MTD_WRITEABLE;
		printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
			part->name);
	}

	slave->ecclayout = master->ecclayout;
	slave->ecc_step_size = master->ecc_step_size;
	slave->ecc_strength = master->ecc_strength;
	slave->bitflip_threshold = master->bitflip_threshold;

	if (master->_block_isbad) {
		uint64_t offs = 0;

		while (offs < slave->size) {
			if (mtd_block_isbad(master, offs + slave->offset))
				slave->ecc_stats.badblocks++;
			offs += slave->erasesize;
		}
	}

out_register:
	return slave;
}

#ifndef __UBOOT__
int mtd_add_partition(struct mtd_info *master, const char *name,
		      long long offset, long long length)
{
	struct mtd_partition part;
	struct mtd_info *p, *new;
	uint64_t start, end;
	int ret = 0;

	/* the direct offset is expected */
	if (offset == MTDPART_OFS_APPEND ||
	    offset == MTDPART_OFS_NXTBLK)
		return -EINVAL;

	if (length == MTDPART_SIZ_FULL)
		length = master->size - offset;

	if (length <= 0)
		return -EINVAL;

	part.name = name;
	part.size = length;
	part.offset = offset;
	part.mask_flags = 0;
	part.ecclayout = NULL;

	new = allocate_partition(master, &part, -1, offset);
	if (IS_ERR(new))
		return PTR_ERR(new);

	start = offset;
	end = offset + length;

	mutex_lock(&mtd_partitions_mutex);
	list_for_each_entry(p, &master->partitions, node) {
		if (start >= p->offset &&
		    (start < (p->offset + p->size)))
			goto err_inv;

		if (end >= p->offset &&
		    (end < (p->offset + p->size)))
			goto err_inv;
	}

	list_add_tail(&new->node, &master->partitions);
	mutex_unlock(&mtd_partitions_mutex);

	add_mtd_device(new);

	return ret;
err_inv:
	mutex_unlock(&mtd_partitions_mutex);
	free_partition(new);
	return -EINVAL;
}
EXPORT_SYMBOL_GPL(mtd_add_partition);

int mtd_del_partition(struct mtd_info *master, int partno)
{
	struct mtd_info *slave, *next;
	int ret = -EINVAL;

	mutex_lock(&mtd_partitions_mutex);
	list_for_each_entry_safe(slave, next, &master->partitions, node)
		if (slave->index == partno) {
			ret = del_mtd_device(slave);
			if (ret < 0)
				break;

			list_del(&slave->node);
			free_partition(slave);
			break;
		}
	mutex_unlock(&mtd_partitions_mutex);

	return ret;
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
#endif

/*
 * This function, given a master MTD object and a partition table, creates
 * and registers slave MTD objects which are bound to the master according to
 * the partition definitions.
 *
 * We don't register the master, or expect the caller to have done so,
 * for reasons of data integrity.
 */

int add_mtd_partitions(struct mtd_info *master,
		       const struct mtd_partition *parts,
		       int nbparts)
{
	struct mtd_info *slave;
	uint64_t cur_offset = 0;
	int i;

	debug("Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);

	for (i = 0; i < nbparts; i++) {
		slave = allocate_partition(master, parts + i, i, cur_offset);
		if (IS_ERR(slave))
			return PTR_ERR(slave);

		mutex_lock(&mtd_partitions_mutex);
		list_add_tail(&slave->node, &master->partitions);
		mutex_unlock(&mtd_partitions_mutex);

		add_mtd_device(slave);

		cur_offset = slave->offset + slave->size;
	}

	return 0;
}

#if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(OF_CONTROL)
int add_mtd_partitions_of(struct mtd_info *master)
{
	ofnode parts, child;
	int i = 0;

	if (!master->dev && !ofnode_valid(master->flash_node))
		return 0;

	if (master->dev)
		parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions");
	else
		parts = ofnode_find_subnode(master->flash_node, "partitions");

	if (!ofnode_valid(parts) || !ofnode_is_enabled(parts) ||
	    !ofnode_device_is_compatible(parts, "fixed-partitions"))
		return 0;

	ofnode_for_each_subnode(child, parts) {
		struct mtd_partition part = { 0 };
		struct mtd_info *slave;
		fdt_addr_t offset;
		fdt_size_t size;

		if (!ofnode_is_enabled(child))
			continue;

		offset = ofnode_get_addr_size_index_notrans(child, 0, &size);
		if (offset == FDT_ADDR_T_NONE || !size) {
			debug("Missing partition offset/size on \"%s\" partition\n",
			      master->name);
			continue;
		}

		part.name = ofnode_read_string(child, "label");
		if (!part.name)
			part.name = ofnode_read_string(child, "name");

		/*
		 * .mask_flags is used to remove flags in allocate_partition(),
		 * so when "read-only" is present, we add MTD_WRITABLE to the
		 * mask, and so MTD_WRITABLE will be removed on partition
		 * allocation
		 */
		if (ofnode_read_bool(child, "read-only"))
			part.mask_flags |= MTD_WRITEABLE;
		if (ofnode_read_bool(child, "lock"))
			part.mask_flags |= MTD_POWERUP_LOCK;

		part.offset = offset;
		part.size = size;
		part.ecclayout = master->ecclayout;

		slave = allocate_partition(master, &part, i++, 0);
		if (IS_ERR(slave))
			return PTR_ERR(slave);

		mutex_lock(&mtd_partitions_mutex);
		list_add_tail(&slave->node, &master->partitions);
		mutex_unlock(&mtd_partitions_mutex);

		add_mtd_device(slave);
	}

	return 0;
}
#endif /* CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(OF_CONTROL) */

#ifndef __UBOOT__
static DEFINE_SPINLOCK(part_parser_lock);
static LIST_HEAD(part_parsers);

static struct mtd_part_parser *get_partition_parser(const char *name)
{
	struct mtd_part_parser *p, *ret = NULL;

	spin_lock(&part_parser_lock);

	list_for_each_entry(p, &part_parsers, list)
		if (!strcmp(p->name, name) && try_module_get(p->owner)) {
			ret = p;
			break;
		}

	spin_unlock(&part_parser_lock);

	return ret;
}

#define put_partition_parser(p) do { module_put((p)->owner); } while (0)

void register_mtd_parser(struct mtd_part_parser *p)
{
	spin_lock(&part_parser_lock);
	list_add(&p->list, &part_parsers);
	spin_unlock(&part_parser_lock);
}
EXPORT_SYMBOL_GPL(register_mtd_parser);

void deregister_mtd_parser(struct mtd_part_parser *p)
{
	spin_lock(&part_parser_lock);
	list_del(&p->list);
	spin_unlock(&part_parser_lock);
}
EXPORT_SYMBOL_GPL(deregister_mtd_parser);

/*
 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
 * are changing this array!
 */
static const char * const default_mtd_part_types[] = {
	"cmdlinepart",
	"ofpart",
	NULL
};

/**
 * parse_mtd_partitions - parse MTD partitions
 * @master: the master partition (describes whole MTD device)
 * @types: names of partition parsers to try or %NULL
 * @pparts: array of partitions found is returned here
 * @data: MTD partition parser-specific data
 *
 * This function tries to find partition on MTD device @master. It uses MTD
 * partition parsers, specified in @types. However, if @types is %NULL, then
 * the default list of parsers is used. The default list contains only the
 * "cmdlinepart" and "ofpart" parsers ATM.
 * Note: If there are more then one parser in @types, the kernel only takes the
 * partitions parsed out by the first parser.
 *
 * This function may return:
 * o a negative error code in case of failure
 * o zero if no partitions were found
 * o a positive number of found partitions, in which case on exit @pparts will
 *   point to an array containing this number of &struct mtd_info objects.
 */
int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
			 struct mtd_partition **pparts,
			 struct mtd_part_parser_data *data)
{
	struct mtd_part_parser *parser;
	int ret = 0;

	if (!types)
		types = default_mtd_part_types;

	for ( ; ret <= 0 && *types; types++) {
		parser = get_partition_parser(*types);
		if (!parser && !request_module("%s", *types))
			parser = get_partition_parser(*types);
		if (!parser)
			continue;
		ret = (*parser->parse_fn)(master, pparts, data);
		put_partition_parser(parser);
		if (ret > 0) {
			printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
			       ret, parser->name, master->name);
			break;
		}
	}
	return ret;
}
#endif

/* Returns the size of the entire flash chip */
uint64_t mtd_get_device_size(const struct mtd_info *mtd)
{
	if (mtd_is_partition(mtd))
		return mtd->parent->size;

	return mtd->size;
}
EXPORT_SYMBOL_GPL(mtd_get_device_size);
