Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12347C05027 for ; Sun, 12 Feb 2023 15:07:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2A8A185347; Sun, 12 Feb 2023 16:07:18 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=collabora.com 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=collabora.com header.i=@collabora.com header.b="JgKtbu0c"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3493E85011; Sun, 12 Feb 2023 16:07:13 +0100 (CET) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) (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 DC4D08552C for ; Sun, 12 Feb 2023 16:07:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=collabora.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjoerd@collabora.com Received: from beast.luon.net (unknown [IPv6:2a10:3781:2531::8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sjoerd) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4A8796602123; Sun, 12 Feb 2023 15:07:09 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1676214429; bh=dBHtzijpY3HfFvPdJEHdtol5uKoAyuzUKyhhzO1MJwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JgKtbu0cDOjsdkMyGh7gQwyo7o4zEvrLGlze1RS6hFWe9G+xjmWlK6Pc9r0MkZ1Jc Kbr7ZoXplMiKK0D7T0JMQr/uOWgst+0E04MbW0CKz8MADsnXZoCfwjcfZmkopNk7Xs C16Yj/NhArV7A0hwM8+Erdp/avWDEuKZUnVGqmQ4jI2pTrOwb0Ur3x2dWvG3FyhDvB WOnn4U1DT6Uhl5S5CIj4OB1JLpj5YpECugHMN0Y3D5L9eWZffxh9gXZ370AyGUQDYc aiBQgT+sp53BIL2ANYyfJ2HH2xTmYWOFcp7BhJ5ydBQz5MeO2bnMNQ9GMq6J1G0IgS 7zHPamQcmeq1g== Received: by beast.luon.net (Postfix, from userid 1000) id 3BDD96A72082; Sun, 12 Feb 2023 16:07:07 +0100 (CET) From: Sjoerd Simons To: Tom Rini Cc: Ashok Reddy Soma , Heinrich Schuchardt , Michal Simek , Patrice Chotard , u-boot@lists.denx.de Subject: [PATCH v2 1/1] lmb: Treat a region which is a subset as equal Date: Sun, 12 Feb 2023 16:07:05 +0100 Message-Id: <20230212150706.2967007-2-sjoerd@collabora.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230212150706.2967007-1-sjoerd@collabora.com> References: <20230212150706.2967007-1-sjoerd@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean In various cases logical memory blocks are coalesced; As a result doing a strict check whether memory blocks are the same doesn't necessarily work as a previous addition of a given block might have been merged into a bigger block. Fix this by considering a block is already registered if it's a pure subset of one of the existing blocks. Signed-off-by: Sjoerd Simons --- Changes in v2: - Adjust calculation to prevent integer overview (fixes lmb tests) lib/lmb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/lmb.c b/lib/lmb.c index f447c639a60..2444b2a6212 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -247,8 +247,10 @@ static long lmb_add_region_flags(struct lmb_region *rgn, phys_addr_t base, phys_addr_t rgnbase = rgn->region[i].base; phys_size_t rgnsize = rgn->region[i].size; phys_size_t rgnflags = rgn->region[i].flags; + phys_addr_t end = base + size - 1; + phys_addr_t rgnend = rgnbase + rgnsize - 1; - if (rgnbase == base && rgnsize == size) { + if (rgnbase <= base && end <= rgnend) { if (flags == rgnflags) /* Already have this region, so we're done */ return 0; -- 2.39.1