Skip to contentSkip to conversation

mtd: ubi: remove redundant check on bytes_left at end of function

PATCH In review Colin Ian King 2 participants 2 messages Nov 7, 2024 – Nov 8, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: ubi: remove redundant check on bytes_left at end of function

In function ubi_nvmem_reg_read the while-loop can only be exiting of bytes_left is zero or an error has occurred. There is an exit return path if an error occurs, so the bytes_left can only be zero after that point. Hence the check for a non-zero bytes_left at the end of the function is redundant and can be removed. Remove the check and just return 0.

---
 drivers/mtd/ubi/nvmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/ubi/nvmem.c +1 -1
index a94a1a9aaec1..34f8c1d3cdee 100644
@@ -55,7 +55,7 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
 	if (err)
 		return err;
 
-	return bytes_left == 0 ? 0 : -EIO;
+	return 0;
 }
 
 static int ubi_nvmem_add(struct ubi_volume_info *vi)
Signature · 1 line
2.39.5
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Colin Ian King

In function ubi_nvmem_reg_read the while-loop can only be exiting of bytes_left is zero or an error has occurred. There is an exit return path if an error occurs, so the bytes_left can only be zero after that point. Hence the check for a non-zero bytes_left at the end of the function is redundant and can be removed. Remove the check and just return 0.

Quoted 5 lines
---
  drivers/mtd/ubi/nvmem.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Make sense.

Quoted 14 lines
drivers/mtd/ubi/nvmem.c +1 -1
index a94a1a9aaec1..34f8c1d3cdee 100644
@@ -55,7 +55,7 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
  	if (err)
  		return err;
 
-	return bytes_left == 0 ? 0 : -EIO;
+	return 0;
  }
 
  static int ubi_nvmem_add(struct ubi_volume_info *vi)