From patchwork Thu Jun 12 06:56:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 895754 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp3163262wrb; Wed, 11 Jun 2025 23:57:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUxp1kJJDnhpf5Sg91Fwni5O6+IdtqlcoCV4LG7DPwBs69VLnz8Nshb0r0vCTxJ75N9P/r0Yw==@linaro.org X-Google-Smtp-Source: AGHT+IH8z1Gz4XDp4HXQmIfKudBrFZLoZ3mjNEVCpNjryMl6AvkD6uypobxkWAlQ9ERI8hGul1Z/ X-Received: by 2002:a17:907:a0c9:b0:ad2:3f54:1834 with SMTP id a640c23a62f3a-adea2712210mr263431766b.40.1749711458516; Wed, 11 Jun 2025 23:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749711458; cv=none; d=google.com; s=arc-20240605; b=XuOb6/J3RxH0Sey5cPDgwY0OOE70JUhSCwtPpCPFcsdxX2ZC8AWTu8RkPotH1SA8Io hPV7Q0n6jbR4ofRqXIy7VutgdZSokWi7Mr6O0jE+ssqs6mT0FRkOCO5Sngz+dbdWAoqv yWWsOaLBmRLTDwTCLMwHAj4sUFR2tFjC6c1yDAf01vKvXppglMPc3PM2No+WwlsK0vgV yDWX7Fqxm5AuzHWcrMn+Lx73fgWMmC6yFWtshtt3qxGpcboduxEG4EZGVwVn1LfCtHRj 4iG37w9yzOImuEZR7xzJazrTEh8DB80yvOj2QXvO+ECqGYlWy8sEAWe1AS4XQPvWSkxO qvPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=tZFm3DvPcI5yXVY2PzhGKJQNwQQNgY8Bo+o6laSNSgI=; fh=OQsgrM7lYcbKid/8QRKDrRnr3aZuZ+FGeYy6ua/5St0=; b=SGVR2yp0/HDkbEvsq0m2KgF/0V3jgs0PlMucoi9CmB1M2thgHGLcDMzjdI91fJwLfX KJThgEOF/R64gIcAVPM+8g3d2OrDp6ednNcg2RM41qy/3KCysf2UuGpjWY3YafrBebCh 6VQ9l0QklFIWo12UrbrwdjJjROsmwRol+/CwKQF8VJ3/SZnnptLXDuAgW3Vu3/5A0PEv nSpG1YcgDSWFTSBJJIvNGeq++Hz7iS/DDCfEq8thUn6GR7Rud2LT6bUmr5tPK77uUo/Y CZNEy1RHegDTKPGJX5+4KzUSbF/anRBn/7yd6he5goYWWVkZh8MtZ/q2CYaF8M32tPzQ vjyQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-adeadf9b076si117164366b.767.2025.06.11.23.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 23:57:38 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2B97B82CA6; Thu, 12 Jun 2025 08:57:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 89B8E82CA6; Thu, 12 Jun 2025 08:57:07 +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=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 8E44D82C84 for ; Thu, 12 Jun 2025 08:57:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F39521C00; Wed, 11 Jun 2025 23:56:44 -0700 (PDT) Received: from a079122.blr.arm.com (a079122.arm.com [10.164.21.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9CEF03F66E; Wed, 11 Jun 2025 23:57:01 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Tom Rini , Casey Connolly , Neil Armstrong , Mark Kettenis , Weijie Gao , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH v4 6/7] mach-snapdragon: add a check before copying FDT to fdt_addr_r Date: Thu, 12 Jun 2025 12:26:23 +0530 Message-Id: <20250612065624.751014-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250612065624.751014-1-sughosh.ganu@linaro.org> References: <20250612065624.751014-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 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 The board_late_init() function allocates memory for a bunch of environment variables, including fdt_addr_r. The device-tree then gets copied to the memory pointed to by fdt_addr_r. However, the memory allocation request can fail, in which case the address that is being written to would not be allocated. Add a check that the memory allocation has succeeded before copying the device-tree. Signed-off-by: Sughosh Ganu --- Changes since V3: New patch arch/arm/mach-snapdragon/board.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index 87a173e0acb..ed2bd5dbade 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -497,7 +497,7 @@ void __weak qcom_late_init(void) /* Stolen from arch/arm/mach-apple/board.c */ int board_late_init(void) { - u32 status = 0; + u32 status = 0, fdt_status = 0; phys_addr_t addr; struct fdt_header *fdt_blob = (struct fdt_header *)gd->fdt_blob; @@ -520,14 +520,19 @@ int board_late_init(void) status |= !lmb_alloc(FASTBOOT_BUF_SIZE, &addr) ? env_set_hex("fastboot_addr_r", addr) : 1; - status |= !lmb_alloc(SZ_2M, &addr) ? + fdt_status |= !lmb_alloc(SZ_2M, &addr) ? env_set_hex("fdt_addr_r", addr) : 1; - if (status) + if (status || fdt_status) log_warning("%s: Failed to set run time variables\n", __func__); /* By default copy U-Boots FDT, it will be used as a fallback */ - memcpy((void *)addr, (void *)gd->fdt_blob, fdt32_to_cpu(fdt_blob->totalsize)); + if (fdt_status) + log_warning("%s: Failed to reserve memory for copying FDT\n", + __func__); + else + memcpy((void *)addr, (void *)gd->fdt_blob, + fdt32_to_cpu(fdt_blob->totalsize)); configure_env(); qcom_late_init();