From patchwork Fri Aug 16 07:33:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mailinglist1@johanneskirchmair.de X-Patchwork-Id: 1973261 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=johanneskirchmair.de header.i=@johanneskirchmair.de header.a=rsa-sha256 header.s=securedbylima-20161106 header.b=UNxiibhO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wljh41mQsz20Bh for ; Fri, 16 Aug 2024 23:36:36 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 224368881C; Fri, 16 Aug 2024 15:36:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=johanneskirchmair.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=johanneskirchmair.de header.i=@johanneskirchmair.de header.b="UNxiibhO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BBE7A88AB9; Fri, 16 Aug 2024 09:35:12 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mx8.mail-out.lima-city.de (mx8.mail-out.lima-city.de [91.216.248.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C548B889A6 for ; Fri, 16 Aug 2024 09:35:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=johanneskirchmair.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=mailinglist1@johanneskirchmair.de From: mailinglist1@johanneskirchmair.de DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=johanneskirchmair.de; s=securedbylima-20161106; t=1723793701; bh=8uE3Qmvf6k6Yk06hdiHErYFH3KV+ItNRixWXAul1KbQ=; h=From:To:Cc:Subject:Date:From; b=UNxiibhOHRsqgpp7Ktscr9BOTrI+yaP61VoYGFSJCwW8nhYSwmkQ6xcj0pwYHfPHL zkYHFpHxfx689p6QuvjPztVQwkqNgUklWa1/jNQzbp6sBhD+tk3LnE6W9DMGjrUu4X gtWlRVhTZZUTwv6ANAhHGpPwP8KY7uwobPnq2osw= To: u-boot@lists.denx.de Cc: trini@konsulko.com, Johannes Kirchmair Subject: [PATCH] spl: fix error handling of spl_fit_read Date: Fri, 16 Aug 2024 09:33:32 +0200 Message-Id: <20240816073332.279025-1-mailinglist1@johanneskirchmair.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 16 Aug 2024 15:36:32 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Johannes Kirchmair Returning negative values from spl_fit_read leads to u-boot crashing. The return value of spl_fit_read is compared with an unsigned value. Returning negative values leads to the check not detecting the error. Not detecting the error leads to crashing. Returning zero in case of an reading error is fine. It indicates that nothing was red. Signed-off-by: Johannes Kirchmair --- common/spl/spl_fat.c | 2 +- include/spl_load.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c index bd8aab253a..345bc55149 100644 --- a/common/spl/spl_fat.c +++ b/common/spl/spl_fat.c @@ -53,7 +53,7 @@ static ulong spl_fit_read(struct spl_load_info *load, ulong file_offset, ret = fat_read_file(filename, buf, file_offset, size, &actread); if (ret) - return ret; + return 0; return actread; } diff --git a/include/spl_load.h b/include/spl_load.h index 1c2b296c0a..b411d9daa1 100644 --- a/include/spl_load.h +++ b/include/spl_load.h @@ -17,8 +17,8 @@ static inline int _spl_load(struct spl_image_info *spl_image, { struct legacy_img_hdr *header = spl_get_load_buffer(-sizeof(*header), sizeof(*header)); - ulong base_offset, image_offset, overhead; - int read, ret; + ulong base_offset, image_offset, overhead, read; + int ret; read = info->read(info, offset, ALIGN(sizeof(*header), spl_get_bl_len(info)), header);