From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796512059; b=xqD+7wMSRRK/tcJkjEAs0n4eQs9Nz3e4WmRopnAVs/WUGQEiVCm0LDYA9/WnvvpLZ13X 74FhqNX8GLpJW84BTzZhhSYNgWGUgW+R/hzqQ7VYhcSpp2S4u1SghiZyCUnJXX6Uqyohh miUKd5w1kM6CvVaOv8t4I9ADJZBun04Bfs7TrRBS+mrQGiVCDYr9nLXp7fNA58xAZTCy6 uMv6oW6x+Hhimgdx13E0yEupDlXla42QeOZ8y3qvYLsHBTYhWB/UNl6MYFmMAIu9ffRsw jiPeTlteaCoiVt/trriGHlqPzeQ8CG1gJ3medr1ZTZlePebRzCd9jPPUmCICJZCzggQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796512059; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=atQqV1JbAEfEy23FJWMxGUxEIE4LksxJc951XnlFvqs=; b=mh2pnvJ5ll5PuVc18CqVNdJVrWXFvo32oJreGkFsy/VcXESPFw8yAEWK21krYDvnM2bi zcSFeZs3Xi+/73VgofXYY2jGBZIxpHp2Aq3aqewy6A8Nv20SSxvcU4SilvdVILuDgSHw/ obQEtQpPI/52k/BuUQUgojInU7MAoRgaLqNIrphxKj0I2LCzCs2QpYOdT3a2vFj1SRVLh WhH3pQZ15ApMry81PrExHbNXnpLfv35riNSeN8L7D2bIe+KpaTDDuVd3S/hO2H9zllYEN zkiqVRO7o6PwWDkYJf4OW9dk5vwxpM4hIRXtw461Zwm/ukmGQElwjiprIhCtvUEKrGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rHHXl5I0; arc=none smtp.remote-ip=209.85.214.179 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1783606A33C for ; Sat, 5 Dec 2026 23:07:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1783606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=rHHXl5I0 Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f0213202fdso12374555ad.3 for ; Sat, 05 Dec 2026 15:07:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796512058; x=1797116858; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=atQqV1JbAEfEy23FJWMxGUxEIE4LksxJc951XnlFvqs=; b=rHHXl5I0nxZ8Qvzg0C/PdleAlZLLcBCVsn09MhPgvBocpygZXiEItS3v2EpDZGjw08 QkGnK11GYBtNlfb44qN7RfsVym6xZuFDOzuXyZy3VwJL/1UGcM2P9SEVKdSUA4xu7U93 DHZ+/iHCjZouEBPs1FfRFYpq0gQAmBzyO0e34jHsBkOpbMpzXuKob+8ZJ2kAKiiId8Du qMTDcziQpeE8c+3Jc/nU3xUlNG195kcFM1QGbSYl+f1UYRijDJ8cGEFoE9zL1jPfbg29 gknZuC9eJ18FRX2VCuUnxVnc87R6v3LLXWDWhWYhn2GBLqcbA90kKAg2zdIDvYCikXrr c5NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796512058; x=1797116858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=atQqV1JbAEfEy23FJWMxGUxEIE4LksxJc951XnlFvqs=; b=KN/05IM2dr7FMa43ZSudn4MtOlyQi6QggG79NMgh8nmltYdl2Kgoy5zja8la926s91 XKodqnEu8BNJNEIHZ+QikoMoT5JQADy09Vrt4iQQXMhP7b5Dk9MAknPDqQP7tIzyfl+p /rgzErGsaBIBMpSawaMWoJTX1jYEuLDENbhw0EZYuRDAfnJEQASCpN51ZRIi8PsJtEHv T2x8h+MbxPMxtRFEfyj11trBG7eIpW3tykL4k5qERSJRlpNlAIBe7MAgLLMSKGLnGlxy uCNIDXZUl/jaCj5GKhnS6Ik3iWRBKGyt/jVeSmSOVHtCoz6oFGpZbEtRH+A+mGKvkowa Fdeg== X-Gm-Message-State: AB4q+uFSWwdgp3nn6yc83GeNliA0awfq+1K6lugwIy/F5CCp4cTScOmN RPWtZ/T7qR/mcps5TKR/D7Mh4E1DLpaDApiGztfGNYjpCwt15doaZb/YAHVIPVPG X-Gm-Gg: AZFdTZecwV2AvQPKZj3V1nEqyXycjdip3ZOzICE7RyZc6b9rG8D2NKaoqpSQUv4QUlz ynHoEVjL0pKf55+S4COjh2mN+nf8qQ6JCg9s/bWZWXryR3Zzy64dHYyU9T+iprLHAJYCRH759fb Y1Bhw/tfvGJ28k0B6p4aMCyP475Lc8jeAIdI4zrj6ZF74l6XpJ6b2WW6QD4gFbQBMqdJdILJ0YE YFgS31Fvbm/af7IqZtO6R5HjSWZ3VsBq8IY52eadAYk68riE7G3IEEQ6R1e7AkyLGxdopAa/O1o BT5RFKzZrpFtePumQ1bb/Upy0VOs7cMmJNaDT1Vs3MXZ1kN44eZbln0z2s0D5NS7z/eAG7HvKsw N+bLqam5abm1fNHpFR6z3Wp01gZJTmHKE5S5QM1uon9nX5d64gAmzF0B5CpnR07f8FCDIGYpWtG op6vl6YvWaIkwm4VotePzMx/kCURtv1hv4xdFxC9V9ZE3igtZwQOLwOX1Mct03M/2eZuBFHuW/+ bNEi+fHumf0rt3K+vh8/1Sz4F75Wx6uJCN5cCqZTTHjz83ARygBGFgWsXMPYDryUP4087GhDyFw pEXbybqd31IeTTDOVjIDQaJy4w/2pF2wE+JSkjt9tA57Awrt+U59ptImAEW/r26odj6rRLGVF1W w6ag3sWjsEtr65WDVFgZX7XfM9WL0NeeGFk1IuJfDVkh4mPwC0Yl7rYDDsvgS6ZFz X-Received: by 2002:a17:903:38c5:b0:2e9:4b65:369f with SMTP id d9443c01a7336-2f1ba195dc2mr57846075ad.34.1796512058132; Sat, 05 Dec 2026 15:07:38 -0800 (PST) Received: from localhost.localdomain (2001-b011-7000-3d44-f9db-4d6a-9586-a354.dynamic-ip6.hinet.net. [2001:b011:7000:3d44:f9db:4d6a:9586:a354]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b784da61sm30385095ad.1.2026.12.05.15.07.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 05 Dec 2026 15:07:37 -0800 (PST) From: Jyun-An Chen To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Jyun-An Chen Subject: [PATCH 2/2] lib/btree: stop btree_get_prev() from wrapping around below key 0 Date: Sun, 6 Dec 2026 07:07:23 +0800 Message-ID: <20261205230723.96179-3-jun930436@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261205230723.96179-1-jun930436@gmail.com> References: <20261205230723.96179-1-jun930436@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When btree_get_prev() finds no smaller key in the leaf it descended to, it retries the search below retry_key, the key of the last inner node entry it followed. Inner node keys are not updated when entries are removed, and find_level() lowers the rightmost inner key to the key it looks for, so that key can be 0 while the tree has no entry with key 0: after key 0 was removed, or after btree_remove() was called for a key 0 that was not in the tree. dec_key() then wraps it around to the largest possible key, and the search starts over at the end of the tree. A btree_for_each_safe*() loop that reaches the bottom of such a tree never terminates. For example, with keys 0..51 in a btree32, removing key 0 and then walking the tree with btree_last() and btree_get_prev() returns 51..1, then 51..1 again, without end. There is no key below 0, so stop when retry_key is 0. Fixes: 5db53f3e80de ("[LogFS] add new flash file system") Signed-off-by: Jyun-An Chen --- I used an AI coding assistant (Claude Code) to write simple tests to check that this change works. lib/btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/btree.c b/lib/btree.c index 3c2560173c62..c245a14c31bf 100644 --- a/lib/btree.c +++ b/lib/btree.c @@ -346,7 +346,7 @@ void *btree_get_prev(struct btree_head *head, struct btree_geo *geo, } } miss: - if (retry_key) { + if (retry_key && !keyzero(geo, retry_key)) { longcpy(key, retry_key, geo->keylen); retry_key = NULL; goto retry;