From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B69282F24 for ; Wed, 12 Apr 2023 08:45:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D869C433EF; Wed, 12 Apr 2023 08:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1681289114; bh=8gfrCR1qp1VpjbBpK+SpbTH9F41a7WxNrjlNCn5vQHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHqlS0I47/yZJCoeVd8XgG2Z/4g3H2v5dsAf0TNzHQCz3O4Ip+lmWkKA2nteUuBVG YTou/i56EILdgXMOSVe1FZhfYX1hgevobttJPFRbojtIz0wTTY58sczTNe3yxW2nPs 7Hj/LmbjaS4s8h/v7zTV0GQlj3SJVtPjFH9DkHxQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Peng Zhang , "Liam R. Howlett" , Andrew Morton Subject: [PATCH 6.1 140/164] maple_tree: fix get wrong data_end in mtree_lookup_walk() Date: Wed, 12 Apr 2023 10:34:22 +0200 Message-Id: <20230412082842.560272854@linuxfoundation.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412082836.695875037@linuxfoundation.org> References: <20230412082836.695875037@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Peng Zhang commit ec07967d7523adb3670f9dfee0232e3bc868f3de upstream. if (likely(offset > end)) max = pivots[offset]; The above code should be changed to if (likely(offset < end)), which is correct. This affects the correctness of ma_data_end(). Now it seems that the final result will not be wrong, but it is best to change it. This patch does not change the code as above, because it simplifies the code by the way. Link: https://lkml.kernel.org/r/20230314124203.91572-1-zhangpeng.00@bytedance.com Link: https://lkml.kernel.org/r/20230314124203.91572-2-zhangpeng.00@bytedance.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- lib/maple_tree.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3870,18 +3870,13 @@ static inline void *mtree_lookup_walk(st end = ma_data_end(node, type, pivots, max); if (unlikely(ma_dead_node(node))) goto dead_node; - - if (pivots[offset] >= mas->index) - goto next; - do { - offset++; - } while ((offset < end) && (pivots[offset] < mas->index)); - - if (likely(offset > end)) - max = pivots[offset]; + if (pivots[offset] >= mas->index) { + max = pivots[offset]; + break; + } + } while (++offset < end); -next: slots = ma_slots(node, type); next = mt_slot(mas->tree, slots, offset); if (unlikely(ma_dead_node(node)))