Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c0dba44 authored by Brian Norris's avatar Brian Norris
Browse files

mtd: spi-nor: silently drop lock/unlock for already locked/unlocked region



If, for instance, the entire flash is already unlocked and I try to
mtd_unlock() the entire device, I don't expect to see an EINVAL error.
It should just silently succeed. Ditto for mtd_lock().

Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
Reviewed-by: default avatarEzequiel Garcia <ezequiel@vanguardiasur.com.ar>
Tested-by: default avatarEzequiel Garcia <ezequiel@vanguardiasur.com.ar>
parent edf891ef
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -515,8 +515,12 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)


	status_new = (status_old & ~mask) | val;
	status_new = (status_old & ~mask) | val;


	/* Don't bother if they're the same */
	if (status_new == status_old)
		return 0;

	/* Only modify protection if it will not unlock other areas */
	/* Only modify protection if it will not unlock other areas */
	if ((status_new & mask) <= (status_old & mask))
	if ((status_new & mask) < (status_old & mask))
		return -EINVAL;
		return -EINVAL;


	write_enable(nor);
	write_enable(nor);
@@ -569,8 +573,12 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)


	status_new = (status_old & ~mask) | val;
	status_new = (status_old & ~mask) | val;


	/* Don't bother if they're the same */
	if (status_new == status_old)
		return 0;

	/* Only modify protection if it will not lock other areas */
	/* Only modify protection if it will not lock other areas */
	if ((status_new & mask) >= (status_old & mask))
	if ((status_new & mask) > (status_old & mask))
		return -EINVAL;
		return -EINVAL;


	write_enable(nor);
	write_enable(nor);