From patchwork Tue Jun 17 10:43:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 897369 Delivered-To: patch@linaro.org Received: by 2002:adf:9b99:0:b0:3a4:ee3f:8f15 with SMTP id d25csp2074056wrc; Tue, 17 Jun 2025 03:45:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV7s5T0sRKZ21ounbIDoyZfondZsBgGL5fD0WYZqbkssTI9MpozA63bYMYEvRJHHUCT/wk2OA==@linaro.org X-Google-Smtp-Source: AGHT+IFiQpSGZd+nfBHuBs4W6nZm8NZmtzmO/Awk0TltObfs2/dS22xXqWAi5GGy1K2NNAyS80/5 X-Received: by 2002:ac8:5786:0:b0:4a4:2e99:3a92 with SMTP id d75a77b69052e-4a73c5b09eamr210743511cf.38.1750157113833; Tue, 17 Jun 2025 03:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1750157113; cv=none; d=google.com; s=arc-20240605; b=FK9xhDJspCZU4PqlDOCxBqxf05SNT48wdLjDm9G2Psj2MpO/yMAQiQPx70llobO2Id OYOrSLGhtUhVFbhZzzxHwDGVU0/IVMZgLCBUB7ERUPQew8PVSdbRt87mdw6miDTL74n+ +KsftSx/H1vlDelUNfhpVedH39MPJw873ag96Wt7VOXVoXXrm4VIKTQCXA/j4i+NyAcJ jXBCghl/0dPfs+wJtkY2PAulkiBhT+wEW63SOR0TijP8DEVl0I7Vq6uPA3JQ+T18HQj0 dNaYBHSvFtLheOA55MmnGQj1bBXKyR7wEEjlgHVBeRTf2pRIkrEqIluOc6vGZ+PRhaS0 vIJQ== 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=fNwfvoBmo5/kNqbuNZY4MvxXhgwNLIRQtyXLEM4IJms=; fh=OQsgrM7lYcbKid/8QRKDrRnr3aZuZ+FGeYy6ua/5St0=; b=QhPt4+4F7Wn9yK/ltOCsqt/PqaZ7SFYqYi3csdXfHm9NM0uBLl6DqxFP0gNERfXY3d Dl7lGKxOzw1+AaTRfE4evmy+2ZcEZaj6lr68extf8Bh9sN+jaNyaSPZgp0vVHwqM2s3B Y65uaJu2SqZPJdHGJrsmtgyaG/zhILMRyp3bfZCUAYSR1CUwPXwJtWvQJrBBCHZuk3aL 8dESuKggvUEX97CgU3v8ld2z7o9B2A2KOF9e5LVMAsX5CI4XOt1h8fcecAWFUwsH6UfQ oLEkpEs5t/PYw9MQb8n7vjT9iiCiWDt2S9Hhr2renSTeWKd5E2y+zjMN0ls8yOa7g67r m2Og==; 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 d75a77b69052e-4a72a4e4f0bsi124410051cf.450.2025.06.17.03.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 03:45:13 -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 9EBB382C79; Tue, 17 Jun 2025 12:44:31 +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 D997C82BA1; Tue, 17 Jun 2025 12:44:29 +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 D7AB682E08 for ; Tue, 17 Jun 2025 12:44:27 +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 378C91596; Tue, 17 Jun 2025 03:44:06 -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 0D30B3F58B; Tue, 17 Jun 2025 03:44:23 -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 v5 6/7] mach-snapdragon: add a check before copying FDT to fdt_addr_r Date: Tue, 17 Jun 2025 16:13:45 +0530 Message-Id: <20250617104346.1379981-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250617104346.1379981-1-sughosh.ganu@linaro.org> References: <20250617104346.1379981-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 V4: None 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();