From patchwork Mon Mar 3 13:32:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 869837 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp2122700wrz; Mon, 3 Mar 2025 05:34:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU2JRrFOIMpbK7MG7CJ6WSHeNXYZMh8mQYobjDHIny91i2gbAbScFdH3OUBFtm3kR51jMxVNg==@linaro.org X-Google-Smtp-Source: AGHT+IGa1ouDCwomh+xo36itmOWYBSjpvPx1dnQbIz9S8gfzkmD7jfBegIYo4/WBfGFG4MCDcuNS X-Received: by 2002:a05:6a21:4d14:b0:1f1:42f:5a3a with SMTP id adf61e73a8af0-1f2e389c8ccmr29046519637.9.1741008845556; Mon, 03 Mar 2025 05:34:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741008845; cv=none; d=google.com; s=arc-20240605; b=OApPxG6r699qJsBvG5w2awfk9ePvIpFxP1gWrj9t+vQAOlQLKyxb9Svvvzd19XRv2e T+VKnKm6IkZ2rpDVmPRVzmI6b6sS/5G2C9dNpa1vQrBNN3KANEErTg3PmkinVB+N2m0n jrEc4RwO5aoLpgCy6H3x6YuPntIpKXlU4byDB3gS0kGfpV14xOuY0iTCDuRv4k5j2prv yJ6pr17X46UkgAx9m3vkis42JAp33nKIzSK9UzaUTKg0C0f1JRRuIcnfLG8y71K/mI+k LW7QU7mSfLLSkMsmdz6Oz+ompAu16IP0VnXOclxFjqLMqjR2e+EcRxaCiburJkFGSwGB QppA== 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=qooCdfkgAt2MOZ8GVriPD2oaFNM3aowBH6Yv+GjMpTg=; fh=2HGKihHUAicyV3F+aHiaoPpwvqWA0zlC04Ew6QaQoEg=; b=EeDTWZJ/STumJit/bMrYusj0GiZErxrzoitdpxumJMnLjfTpQvZEGLn82HR1Bk0vP0 wrFxPrnV9iktF2ZzGpY7OEeHTQhbnF/5ws79/HKopRpG/xVKzc1+QtiEN/q5nGNE7GhO EjsFnJL/ddEkXrHflVzi2no+5KZiUgr5H54s60/hTld3emqVglJe6VuTcOAfQxgALtGH iKRG/KQUvL/hpbQM2VbF3n9e5hiClFvtmyOGTZN95ZBRpK87iYwGCYwHhiFqnAfr7Lbt v16+dgWdVcb5BiKljv4ZwoppyoOJE4/ar6cTS+7y9vuKHqexOQ3xVzgv93ipLtXhuszs TyvQ==; 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 41be03b00d2f7-af1801575desi9013217a12.62.2025.03.03.05.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 05:34:05 -0800 (PST) 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 ED9CB81280; Mon, 3 Mar 2025 14:33:14 +0100 (CET) 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 AC37981335; Mon, 3 Mar 2025 14:33:14 +0100 (CET) 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 5F9B681280 for ; Mon, 3 Mar 2025 14:33:12 +0100 (CET) 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 E3FBD113E; Mon, 3 Mar 2025 05:33:25 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4BC763F673; Mon, 3 Mar 2025 05:33:09 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Tom Rini , Quentin Schulz , Udit Kumar , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 6/6] lmb: optimise the lmb allocation functions Date: Mon, 3 Mar 2025 19:02:31 +0530 Message-Id: <20250303133231.405279-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250303133231.405279-1-sughosh.ganu@linaro.org> References: <20250303133231.405279-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 actual logic to allocate a region of memory is in the _lmb_alloc_base() function. The lmb_alloc() API function calls lmb_alloc_base(), which then calls _lmb_alloc_base() to do the allocation. Instead, call the _lmb_alloc_base() directly from both the allocation API's, and move the error message to the _lmb_alloc_base(). Signed-off-by: Sughosh Ganu --- Changes since V2: * Change the print for allocation failure into a debug message as per suggestion from Heinrich lib/lmb.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index b42a512f6c0..981ea1b2ca0 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -724,26 +724,22 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align, base = ALIGN_DOWN(res_base - size, align); } } + + log_debug("%s: Failed to allocate 0x%lx bytes below 0x%lx\n", + __func__, (ulong)size, (ulong)max_addr); + return 0; } phys_addr_t lmb_alloc(phys_size_t size, ulong align) { - return lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE, LMB_NONE); + return _lmb_alloc_base(size, align, LMB_ALLOC_ANYWHERE, LMB_NONE); } phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr, uint flags) { - phys_addr_t alloc; - - alloc = _lmb_alloc_base(size, align, max_addr, flags); - - if (alloc == 0) - printf("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", - (ulong)size, (ulong)max_addr); - - return alloc; + return _lmb_alloc_base(size, align, max_addr, flags); } phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size, u32 flags)