diff mbox series

mtd-interface: Properly handle flash devices without lock support

Message ID 20190110123814.14545-1-mike.looijmans@topic.nl
State Accepted
Headers show
Series mtd-interface: Properly handle flash devices without lock support | expand

Commit Message

Mike Looijmans Jan. 10, 2019, 12:38 p.m. UTC
mtd_is_locked() returns a negative value if the flash driver does not support
(or require) locking. In that case, the flash routine should not attempt to
call further (un)lock functions, they will only result in logging like this:

libmtd: error!: MEMUNLOCK ioctl failed for eraseblock 20 (mtd4)
        error 95 (Operation not supported)

To fix the issue, check that the return value is above zero.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
---
 corelib/mtd-interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Babic Jan. 30, 2019, 4:56 p.m. UTC | #1
Hi Mike,

On 10/01/19 13:38, Mike Looijmans wrote:
> mtd_is_locked() returns a negative value if the flash driver does not support
> (or require) locking. In that case, the flash routine should not attempt to
> call further (un)lock functions, they will only result in logging like this:
> 
> libmtd: error!: MEMUNLOCK ioctl failed for eraseblock 20 (mtd4)
>         error 95 (Operation not supported)
> 
> To fix the issue, check that the return value is above zero.
> 
> Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
> ---
>  corelib/mtd-interface.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
> index 7ea9bb4..ccbe178 100644
> --- a/corelib/mtd-interface.c
> +++ b/corelib/mtd-interface.c
> @@ -83,7 +83,7 @@ int flash_erase(int mtdnum)
>  		}
>  
>  		/* Unlock memory if required */
> -		if (mtd_is_locked(mtd, fd, eb)) {
> +		if (mtd_is_locked(mtd, fd, eb) > 0) {
>  			if (mtd_unlock(mtd, fd, eb) != 0) {
>  				if (errno != EOPNOTSUPP) {
>  					TRACE("%s: MTD unlock failure", mtd_device);
> 

Applied to master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c
index 7ea9bb4..ccbe178 100644
--- a/corelib/mtd-interface.c
+++ b/corelib/mtd-interface.c
@@ -83,7 +83,7 @@  int flash_erase(int mtdnum)
 		}
 
 		/* Unlock memory if required */
-		if (mtd_is_locked(mtd, fd, eb)) {
+		if (mtd_is_locked(mtd, fd, eb) > 0) {
 			if (mtd_unlock(mtd, fd, eb) != 0) {
 				if (errno != EOPNOTSUPP) {
 					TRACE("%s: MTD unlock failure", mtd_device);