Skip to contentSkip to conversation

mtd: nand: raw: atmel: remove unnecessary return value

PATCH In review Marcus Folkesson 3 participants 8 messages Aug 9, 2024 – Dec 10, 2024

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

PATCH 1/1 mtd: nand: raw: atmel: remove unnecessary return value

The condition 'ret' is always true as it is never set to other than -EIO.

Remove 'ret' and the condition for copy.

---

 drivers/mtd/nand/raw/atmel/nand-controller.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/mtd/nand/raw/atmel/nand-controller.c +2 -8
index ee4ec6da58..00d7e177b9 100644
@@ -568,12 +568,9 @@ static void atmel_nfc_copy_to_sram(struct nand_chip *chip, const u8 *buf,
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct atmel_nand *nand = to_atmel_nand(chip);
 	struct atmel_hsmc_nand_controller *nc;
-	int ret = -EIO;
 
 	nc = to_hsmc_nand_controller(nand->controller);
-
-	if (ret)
-		memcpy_toio(nc->sram.virt, buf, mtd->writesize);
+	memcpy_toio(nc->sram.virt, buf, mtd->writesize);
 
 	if (oob_required)
 		memcpy_toio(nc->sram.virt + mtd->writesize, chip->oob_poi,
@@ -586,12 +583,9 @@ static void atmel_nfc_copy_from_sram(struct nand_chip *chip, u8 *buf,
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct atmel_nand *nand = to_atmel_nand(chip);
 	struct atmel_hsmc_nand_controller *nc;
-	int ret = -EIO;
 
 	nc = to_hsmc_nand_controller(nand->controller);
-
-	if (ret)
-		memcpy_fromio(buf, nc->sram.virt, mtd->writesize);
+	memcpy_fromio(buf, nc->sram.virt, mtd->writesize);
 
 	if (oob_required)
 		memcpy_fromio(chip->oob_poi, nc->sram.virt + mtd->writesize,
Signature · 1 line
2.45.1
#1 lore raw

Hello Marcus,

Am Fri, Aug 09, 2024 at 02:15:43PM +0200 schrieb Marcus Folkesson:

Quoted 2 lines

The condition 'ret' is always true as it is never set to other than -EIO.

Technically, you're right.

I quickly compared with the same driver in Linux. That has some additional lines for DMA transfers which probably got removed when porting the driver.

Does the code before your patch throw compiler warnings? If not, I would keep it as is. The compiler will probably optimize it away anyway, and it would make future ports from Linux easier.

Greets
Alex

Quoted 44 lines

Remove 'ret' and the condition for copy.

---

 drivers/mtd/nand/raw/atmel/nand-controller.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/mtd/nand/raw/atmel/nand-controller.c +2 -8
index ee4ec6da58..00d7e177b9 100644
@@ -568,12 +568,9 @@ static void atmel_nfc_copy_to_sram(struct nand_chip *chip, const u8 *buf,
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct atmel_nand *nand = to_atmel_nand(chip);
 	struct atmel_hsmc_nand_controller *nc;
-	int ret = -EIO;
 
 	nc = to_hsmc_nand_controller(nand->controller);
-
-	if (ret)
-		memcpy_toio(nc->sram.virt, buf, mtd->writesize);
+	memcpy_toio(nc->sram.virt, buf, mtd->writesize);
 
 	if (oob_required)
 		memcpy_toio(nc->sram.virt + mtd->writesize, chip->oob_poi,
@@ -586,12 +583,9 @@ static void atmel_nfc_copy_from_sram(struct nand_chip *chip, u8 *buf,
 	struct mtd_info *mtd = nand_to_mtd(chip);
 	struct atmel_nand *nand = to_atmel_nand(chip);
 	struct atmel_hsmc_nand_controller *nc;
-	int ret = -EIO;
 
 	nc = to_hsmc_nand_controller(nand->controller);
-
-	if (ret)
-		memcpy_fromio(buf, nc->sram.virt, mtd->writesize);
+	memcpy_fromio(buf, nc->sram.virt, mtd->writesize);
 
 	if (oob_required)
 		memcpy_fromio(chip->oob_poi, nc->sram.virt + mtd->writesize,
Signature · 1 line
2.45.1
#2 lore raw

Hi all

Quoted 9 lines · Alexander Dahl

Hello Marcus,

Am Fri, Aug 09, 2024 at 02:15:43PM +0200 schrieb Marcus Folkesson:

Quoted 2 lines

The condition 'ret' is always true as it is never set to other than -EIO.

Technically, you're right.

Quoted 8 lines

I quickly compared with the same driver in Linux. That has some additional lines for DMA transfers which probably got removed when porting the driver.

Does the code before your patch throw compiler warnings? If not, I would keep it as is. The compiler will probably optimize it away anyway, and it would make future ports from Linux easier.

I suggest to comment it because it will happen to other people to send a similar patch

Michael

Quoted 47 lines

Greets
Alex

Quoted 44 lines

Remove 'ret' and the condition for copy.

---

 drivers/mtd/nand/raw/atmel/nand-controller.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/mtd/nand/raw/atmel/nand-controller.c +2 -9
index ee4ec6da58..00d7e177b9 100644
@@ -568,12 +568,9 @@ static void atmel_nfc_copy_to_sram(struct nand_chip *chip, const u8 *buf,
      struct mtd_info *mtd = nand_to_mtd(chip);
      struct atmel_nand *nand = to_atmel_nand(chip);
      struct atmel_hsmc_nand_controller *nc;
-     int ret = -EIO;
 
      nc = to_hsmc_nand_controller(nand->controller);
-
-     if (ret)
-             memcpy_toio(nc->sram.virt, buf, mtd->writesize);
+     memcpy_toio(nc->sram.virt, buf, mtd->writesize);
 
      if (oob_required)
              memcpy_toio(nc->sram.virt + mtd->writesize, chip->oob_poi,
@@ -586,12 +583,9 @@ static void atmel_nfc_copy_from_sram(struct nand_chip *chip, u8 *buf,
      struct mtd_info *mtd = nand_to_mtd(chip);
      struct atmel_nand *nand = to_atmel_nand(chip);
      struct atmel_hsmc_nand_controller *nc;
-     int ret = -EIO;
 
      nc = to_hsmc_nand_controller(nand->controller);
-
-     if (ret)
-             memcpy_fromio(buf, nc->sram.virt, mtd->writesize);
+     memcpy_fromio(buf, nc->sram.virt, mtd->writesize);
 
      if (oob_required)
              memcpy_fromio(chip->oob_poi, nc->sram.virt + mtd->writesize,
--

2.45.1

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#3 lore raw
In reply to Alexander Dahl

Hello Alexander,

Thanks for fast response!

Quoted 11 lines · Alexander Dahl

Hello Marcus,

Am Fri, Aug 09, 2024 at 02:15:43PM +0200 schrieb Marcus Folkesson:

Quoted 2 lines

The condition 'ret' is always true as it is never set to other than -EIO.

Technically, you're right.

I quickly compared with the same driver in Linux. That has some additional lines for DMA transfers which probably got removed when porting the driver.

Yes, I thought is was something like that.

Quoted 2 lines

Does the code before your patch throw compiler warnings? If not, I

Not the compiler, but vim-ale (lint engine) is yelling loudly at me.

Quoted 2 lines

would keep it as is. The compiler will probably optimize it away anyway, and it would make future ports from Linux easier.

I understand your reasoning but not sure I agree.

I don't think it significantly complicates any porting and the code becomes cleaner.

I also think that the porting become less error-prone because it becomes a conscious choice to introduce and use ret if needed.

That is what I think, but I don't really have a very strong opinion about it.

Quoted 4 lines

Greets
Alex

Best regards,
Marcus Folkesson

Reviewed-by Michael Trimarchi
#5 lore raw

Hi Marcus

Quoted 11 lines · Marcus Folkesson
Quoted 7 lines · Marcus Folkesson

The condition 'ret' is always true as it is never set to other than -EIO.

Remove 'ret' and the condition for copy.

---

Any more thoughts on this?

It will be included in the next pull request.

Michael

Quoted 3 lines

Thanks,
Marcus Folkesson

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
#6 lore raw

Hello Michael,

Quoted 11 lines · Michael Nazzareno Trimarchi

Hi Marcus

Quoted 7 lines · Marcus Folkesson
Quoted 5 lines · Marcus Folkesson

The condition 'ret' is always true as it is never set to other than -EIO.

Remove 'ret' and the condition for copy.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

---

Any more thoughts on this?

It will be included in the next pull request.

Not sure it got included?

Quoted 3 lines

Michael

Thanks,
Marcus Folkesson

#7 lore raw

Hi

Il mar 10 dic 2024, 08:08 Marcus Folkesson <[email protected]> ha scritto:

Quoted 18 lines

Hello Michael,

Quoted 14 lines · Michael Nazzareno Trimarchi

Hi Marcus

Quoted 10 lines · Marcus Folkesson
Quoted 7 lines · Marcus Folkesson

The condition 'ret' is always true as it is never set to other than -EIO.

Remove 'ret' and the condition for copy.

---

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Any more thoughts on this?

It will be included in the next pull request.

Not sure it got included?

I will pick today.

Michael

Quoted 8 lines
Quoted 4 lines

Michael

Thanks,
Marcus Folkesson