[PATCH u-boot-marvell v3 06/39] tools: kwboot: Fix kwboot_xm_sendblock() function when kwboot_tty_recv() fails

Stefan Roese sr at denx.de
Fri Oct 1 08:15:24 CEST 2021


On 24.09.21 23:06, Marek Behún wrote:
> From: Pali Rohár <pali at kernel.org>
> 
> When kwboot_tty_recv() fails or times out, it does not set the `c`
> variable to NAK. The variable is then compared, while it holds either
> an undefined value or a value from previous iteration. Set `c` to NAK so
> that the other side will try to resend current block, and remove the
> now unnecessary break.
> 
> In other failure cases return immediately.
> 
> Signed-off-by: Pali Rohár <pali at kernel.org>
> Reviewed-by: Marek Behún <marek.behun at nic.cz>

Reviewed-by: Stefan Roese <sr at denx.de>

Thanks,
Stefan

> ---
>   tools/kwboot.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/kwboot.c b/tools/kwboot.c
> index 454339db14..b9a402ca91 100644
> --- a/tools/kwboot.c
> +++ b/tools/kwboot.c
> @@ -380,12 +380,15 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block)
>   	do {
>   		rc = kwboot_tty_send(fd, block, sizeof(*block));
>   		if (rc)
> -			break;
> +			return rc;
>   
>   		do {
>   			rc = kwboot_tty_recv(fd, &c, 1, blk_rsp_timeo);
> -			if (rc)
> -				break;
> +			if (rc) {
> +				if (errno != ETIMEDOUT)
> +					return rc;
> +				c = NAK;
> +			}
>   
>   			if (c != ACK && c != NAK && c != CAN)
>   				printf("%c", c);
> 


Viele Grüße,
Stefan

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de


More information about the U-Boot mailing list