public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Stefan Roese <sr@denx.de>, Michal Simek <michal.simek@amd.com>,
	Simon Glass <sjg@chromium.org>
Cc: u-boot@lists.denx.de
Subject: [PATCH 2/4] cmd: mvebu/bubt: Correctly propagate failure during tftp transport
Date: Tue, 26 Jul 2022 16:11:57 +0200	[thread overview]
Message-ID: <20220726141159.19774-3-pali@kernel.org> (raw)
In-Reply-To: <20220726141159.19774-1-pali@kernel.org>

net_loop() returns signed int type and negative value represents error.
tftp_read_file() returns unsigned size_t type and zero value represents
error. Casting signed negative value to unsigned size_t type cause losing
information about error and bubt thinks that no error happened, and
continue erasing SPI-NOR which cause malfunction device.

Fix this issue by correctly propagating failure during tftp transport.

With this change when there is no eth link, bubt does not erase SPI-NOR
anymore.

  => bubt
  Burning U-Boot image "flash-image.bin" from "tftp" to "spi"
  ethernet@30000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
  ethernet@30000: No link.
  Error: Failed to read file flash-image.bin from tftp

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 cmd/mvebu/bubt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index a05e22a5479c..2924b1539f32 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -455,11 +455,14 @@ static int is_usb_active(void)
 #ifdef CONFIG_CMD_NET
 static size_t tftp_read_file(const char *file_name)
 {
+	int ret;
+
 	/*
 	 * update global variable image_load_addr before tftp file from network
 	 */
 	image_load_addr = get_load_addr();
-	return net_loop(TFTPGET);
+	ret = net_loop(TFTPGET);
+	return ret > 0 ? ret : 0;
 }
 
 static int is_tftp_active(void)
-- 
2.20.1


  parent reply	other threads:[~2022-07-26 14:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 14:11 [PATCH 0/4] cmd: mvebu/bubt: Improvements for image verification Pali Rohár
2022-07-26 14:11 ` [PATCH 1/4] cmd: mvebu/bubt: Verify image type for all 32-bit Aramda SoCs and Armada 3700 Pali Rohár
2022-07-28  6:36   ` Stefan Roese
2022-07-26 14:11 ` Pali Rohár [this message]
2022-07-28  6:37   ` [PATCH 2/4] cmd: mvebu/bubt: Correctly propagate failure during tftp transport Stefan Roese
2022-07-26 14:11 ` [PATCH 3/4] cmd: mvebu/bubt: Add support for sha512 checksum validation for Armada 3700 Pali Rohár
2022-07-28  6:37   ` Stefan Roese
2022-07-26 14:11 ` [PATCH 4/4] cmd: mvebu/bubt: Fix cmd main return value on error Pali Rohár
2022-07-28  6:38   ` Stefan Roese
2022-07-29 12:02 ` [PATCH 0/4] cmd: mvebu/bubt: Improvements for image verification Stefan Roese

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220726141159.19774-3-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=michal.simek@amd.com \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox