/* Given a number and NULL address, return the num'th entry in the device table, if any. Given an address and num == -1, search the device table for a device with that address and return if it's still present. Given both, return the num'th driver only if its address matches. Return error code if not.  */
struct mtd_info* get_mtd_device(struct mtd_info *mtd, int num)
/* Given a number and NULL address, return the num'th entry in the device table, if any. Given an address and num == -1, search the device table for a device with that address and return if it's still present. Given both, return the num'th driver only if its address matches. Return error code if not.  */
struct mtd_info* get_mtd_device(struct mtd_info *mtd, int num)
{
	struct mtd_info *ret = NULL;
	int i, err = -ENODEV;
	if (num == -1) {
		for (i = 0; i < MAX_MTD_DEVICES; i++)
			if (mtd_table[i] == mtd)
				ret = mtd_table[i];
	} else if (num < MAX_MTD_DEVICES) {
		ret = mtd_table[num];
		if (mtd && mtd != ret)
			ret = NULL;
	}
	if (!ret)
		goto out_unlock;
	ret->usecount++;
	return ret;
out_unlock:
	return ERR_PTR(err);
}