/* Return: 0 on success, a negative error code otherwise.  */
int spinand_select_target(struct spinand_device *spinand, unsigned int target)
/* Return: 0 on success, a negative error code otherwise.  */
int spinand_select_target(struct spinand_device *spinand, unsigned int target)
{
	struct nand_device *nand = spinand_to_nand(spinand);
	int ret;
	if (WARN_ON(target >= nand->memorg.ntargets))
		return -EINVAL;
	if (spinand->cur_target == target)
		return 0;
	if (nand->memorg.ntargets == 1) {
		spinand->cur_target = target;
		return 0;
	}
	ret = spinand->select_target(spinand, target);
	if (ret)
		return ret;
	spinand->cur_target = target;
	return 0;
}