From patchwork Wed Oct 23 15:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 837818 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1f12:b0:37d:45d0:187 with SMTP id hh18csp527878wrb; Wed, 23 Oct 2024 08:22:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUkkK5cNAT6ENiqVt0vikq1ckwkraeqGNvDPqH9mn64Q9Wi3Fs4O6KxWHX58j0nPUoItY68HQ==@linaro.org X-Google-Smtp-Source: AGHT+IGXcMFGgXW9rDE7WD3L7Hw5TghykDdlfVlSc+XJOF33Vq6r0/JJnu3lor00Qjxbyxb5rMOO X-Received: by 2002:a05:651c:198c:b0:2fc:97a8:48f9 with SMTP id 38308e7fff4ca-2fc9d35a491mr16872601fa.19.1729696942302; Wed, 23 Oct 2024 08:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729696942; cv=none; d=google.com; s=arc-20240605; b=ZIRjjDFBz8nyYZYHAT27riLUya7XdJuu5WacN01rxHF1w06Pd44fiDFk7xL+kBDx9M kGEfoAQSjVBDw53uyglUiHEmKKRQqonq/Ckh1Bwiffq+5VXHDzh2AiWyrm3c28wb3U7K zxfWEGeWZMLJsMhkE5IUSsig/kA7TRqc2OWTorN0m1E3Lp8ClHIwbRZEMpyYb5WsIYvE bjkJMD2QNGcgb+urA91qn94W95IM1/C32+XA2yT/kvOuRpKczsdaMYHaFUH/nIDwfs/q wMN8pzBY6oME+kw+CHfoJ43AgXtQFDrnf9Hi0KqNRJJPELh+rAEHmOmg47zcOvmOAyrU Ze6w== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=Pm6+7/NsXinpSFKOdnca6MFUdCL8mHEX4HacqC709XQ=; fh=yIUJoiYHJ2Rv//1uDN4b9/eqWKw3usoIEvzVeFp4aBE=; b=DhMXRQvcT0uo7Mr52TvY5Psrnd4LMM93QL3UJAxO/IxbqnOSIaxn6C6EP7G+bWK6hr Uaz1dYiO5LD+u0OMe2ePTK1/v6OvdY2XNPSn0fnkCWYUd67NQrW/b8RSMlMwkYiUYKYs ZhXRApRf369zj7nzSxFo9NxLoI86RrpSCDqjEVYlO7dmY1e5lcyu1mvCzoDBapij0NCc wgxZ83fa2GUF9mlURx+7Lc90gDesQjSVHdgwehEZDYOb/WJUbw3hcsq7kGrEbl3SeRjo ZMEvPPnMHiidkQCWF7jhpFmPBr4DXWIlMgaK8EQrMzr/zMJV4OrTD+w0tmsR/dobxVSL qAlA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=syTJZXG3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 38308e7fff4ca-2fb9ade6c8fsi23518871fa.194.2024.10.23.08.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=syTJZXG3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 16CE3892D5; Wed, 23 Oct 2024 17:22:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="syTJZXG3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 025F4892CF; Wed, 23 Oct 2024 17:22:15 +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_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2E9F6892DE for ; Wed, 23 Oct 2024 17:22:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a99f1fd20c4so937509766b.0 for ; Wed, 23 Oct 2024 08:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729696927; x=1730301727; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Pm6+7/NsXinpSFKOdnca6MFUdCL8mHEX4HacqC709XQ=; b=syTJZXG3SA/qWZ/IFXrEDgJRQwtCkkJJTB8sSLwOwpHu63QjtSoOX23WF0sXi+rV9D rWAmWE4wZ8VaN3ArDW7USteUMKsBSXFnNLmRGriKASSinR4yx5Pt3u+xK8IX8DtJJxqR VqiPE/yncRlVzXQxZ1Bxw7Jyak7siEs0LgLHdN6G9i7jl3M5BKKa2rnCRE1AyH5KFL3g MWZM2guSkrc5/ReSQG7xAda7bk8A4RVjQVjfph4CdnPIb6SuViBmN8L5WvcTzS/mNQWg xDcwdLk9mUAulpF6z/HOLpkshlQu116K+L9dBpSjzyvdFwp+Thq2F/KqFPaWSd7C9bPR Usgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729696927; x=1730301727; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Pm6+7/NsXinpSFKOdnca6MFUdCL8mHEX4HacqC709XQ=; b=MRMJmA7xWaug0y2w9wvGTYprLr0MPaCI6IgxbV3XjM28UPlCOrdTxXzkYTn69hk/QA PrWhFsrGbIB6KnYf5pDmZlONoq9NbKI1ZsAW8VVelqUZQ04Guu77Z9nlyRTu+xdmIjRb +H9Wuvt0mjH+QUqYXiCsvK6155nd8MxDWsu3C3DUxTkUnoRpwa+h9xB6zm0AXG9FB61x uO8BfbmO94imB3frM8SfCWdPWjeTnz8a6+uPsns8xg/+n8HimgOtfeIlskK0VrunZG3l NX2uOkghPZGPRAyXiCJiItqsDryBCx8uBYU1vkTLfkAHxUVSghCNe99tik7atkefpabn dnPQ== X-Forwarded-Encrypted: i=1; AJvYcCUSMgOwbWP45Hiz1Wv5bV2hErXTCXYyyEwCV+rfbwePNqgnj4T7tylUItSziKGXAUu0Fcmh/l0=@lists.denx.de X-Gm-Message-State: AOJu0YzjGCkEaWMohHSgSxKvdS7kJXAfU/FrywzwbtorV2FOtU/G15Tw t7io69rZPhAdz338X1IOCkUQe/YwVbp+WG+1XgZjaLUoSXW+oGqW9QydRdzUHLc= X-Received: by 2002:a17:906:c154:b0:a9a:12c9:41d1 with SMTP id a640c23a62f3a-a9abf8a2083mr305822766b.28.1729696927511; Wed, 23 Oct 2024 08:22:07 -0700 (PDT) Received: from localhost.localdomain (ppp176092143132.access.hol.gr. [176.92.143.132]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a912edfedsm489242766b.72.2024.10.23.08.22.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 08:22:07 -0700 (PDT) From: Ilias Apalodimas To: sughosh.ganu@linaro.org Cc: Ilias Apalodimas , Tom Rini , Simon Glass , Marek Vasut , Laurent Pinchart , Guillaume La Roque , Matthias Schiffer , Mattijs Korpershoek , u-boot@lists.denx.de Subject: [PATCH 1/2] lmb: Fix lmb_add_region_flags() return codes and testing Date: Wed, 23 Oct 2024 18:22:00 +0300 Message-ID: <20241023152203.1218242-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.45.2 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 function description says this should return 0 or -1 on failures. When regions coalesce though this returns the number of coalescedregions which is confusing and requires special handling of the return code. On top of that no one is using the number of coalesced regions. So let's just return 0 on success and adjust our selftests accordingly Signed-off-by: Ilias Apalodimas Reviewed-by: Caleb Connolly --- boot/image-fdt.c | 2 +- lib/lmb.c | 10 +++++----- test/lib/lmb.c | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 8eda521693dc..eac09059d955 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -73,7 +73,7 @@ static void boot_fdt_reserve_region(u64 addr, u64 size, enum lmb_flags flags) long ret; ret = lmb_reserve_flags(addr, size, flags); - if (ret >= 0) { + if (!ret) { debug(" reserving fdt memory region: addr=%llx size=%llx flags=%x\n", (unsigned long long)addr, (unsigned long long)size, flags); diff --git a/lib/lmb.c b/lib/lmb.c index 7e90f178763b..8ce58fcb9224 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -450,7 +450,7 @@ static long lmb_add_region_flags(struct alist *lmb_rgn_lst, phys_addr_t base, } if (coalesced) - return coalesced; + return 0; if (alist_full(lmb_rgn_lst) && !alist_expand_by(lmb_rgn_lst, lmb_rgn_lst->alloc)) @@ -487,7 +487,7 @@ long lmb_add(phys_addr_t base, phys_size_t size) struct alist *lmb_rgn_lst = &lmb.free_mem; ret = lmb_add_region(lmb_rgn_lst, base, size); - if (ret < 0) + if (ret) return ret; if (lmb_should_notify(LMB_NONE)) @@ -583,8 +583,8 @@ long lmb_reserve_flags(phys_addr_t base, phys_size_t size, enum lmb_flags flags) struct alist *lmb_rgn_lst = &lmb.used_mem; ret = lmb_add_region_flags(lmb_rgn_lst, base, size, flags); - if (ret < 0) - return -1; + if (ret) + return ret; if (lmb_should_notify(flags)) return lmb_map_update_notify(base, size, MAP_OP_RESERVE); @@ -651,7 +651,7 @@ static phys_addr_t _lmb_alloc_base(phys_size_t size, ulong align, if (rgn < 0) { /* This area isn't reserved, take it */ if (lmb_add_region_flags(&lmb.used_mem, base, - size, flags) < 0) + size, flags)) return 0; if (lmb_should_notify(flags)) { diff --git a/test/lib/lmb.c b/test/lib/lmb.c index b2c54fb4bcb8..c917115b7b66 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -473,7 +473,7 @@ static int lib_test_lmb_overlapping_reserve(struct unit_test_state *uts) /* allocate overlapping region should return the coalesced count */ ret = lmb_reserve(0x40011000, 0x10000); - ut_asserteq(ret, 1); + ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x11000, 0, 0, 0, 0); /* allocate 3nd region */ @@ -748,13 +748,13 @@ static int lib_test_lmb_flags(struct unit_test_state *uts) /* merge after */ ret = lmb_reserve_flags(0x40020000, 0x10000, LMB_NOMAP); - ut_asserteq(ret, 1); + ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40010000, 0x20000, 0, 0, 0, 0); /* merge before */ ret = lmb_reserve_flags(0x40000000, 0x10000, LMB_NOMAP); - ut_asserteq(ret, 1); + ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, 0x40000000, 0x30000, 0, 0, 0, 0); @@ -770,7 +770,7 @@ static int lib_test_lmb_flags(struct unit_test_state *uts) /* test that old API use LMB_NONE */ ret = lmb_reserve(0x40040000, 0x10000); - ut_asserteq(ret, 1); + ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 2, 0x40000000, 0x30000, 0x40030000, 0x20000, 0, 0); @@ -789,7 +789,7 @@ static int lib_test_lmb_flags(struct unit_test_state *uts) /* merge with 2 adjacent regions */ ret = lmb_reserve_flags(0x40060000, 0x10000, LMB_NOMAP); - ut_asserteq(ret, 2); + ut_asserteq(ret, 0); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 3, 0x40000000, 0x30000, 0x40030000, 0x20000, 0x40050000, 0x30000);