From patchwork Wed Jul 4 18:23:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 939529 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nic.cz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="JXtaBsDu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41LTrq13YXz9s29 for ; Thu, 5 Jul 2018 04:23:39 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B717BC21FB2; Wed, 4 Jul 2018 18:23:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1FAA6C21C4A; Wed, 4 Jul 2018 18:23:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8EDE7C21C4A; Wed, 4 Jul 2018 18:23:32 +0000 (UTC) Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) by lists.denx.de (Postfix) with ESMTPS id E53B8C21C2F for ; Wed, 4 Jul 2018 18:23:29 +0000 (UTC) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:cac7:3539:7f1f:463]) by mail.nic.cz (Postfix) with ESMTP id 0AD6060102; Wed, 4 Jul 2018 20:23:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1530728609; bh=DWO+d4Tn2sOS22Yy46abV+NvX8QcvcwYb8btrzPfSK8=; h=From:To:Date; b=JXtaBsDuaQ/epMNu9VsJgWQ3h0PFV1K1VWBXrMIGYeo3NbILrZvcaL+JBlGJX8HKR UE1YkgmlU9LMTXT7BECaqAagXKyW44nMvu6zC40ACVm88o92MhivYx89qxeMGhbi9p 6cmvIpXaS6DAYbUdryu0JLd6he3svgxJbDBn+iKI= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de Date: Wed, 4 Jul 2018 20:23:01 +0200 Message-Id: <20180704182301.13241-1-marek.behun@nic.cz> X-Mailer: git-send-email 2.16.4 X-Virus-Scanned: clamav-milter 0.99.2 at mail X-Virus-Status: Clean Cc: Tom Rini Subject: [U-Boot] [PATCH v2] fs: btrfs: Fix wrong comparison in logical to physical mapping X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The comparison logical > item->logical + item->length in btrfs_map_logical_to_physical is wrong and should be instead logical >= item->logical + item->length For example, if item->logical = 4096 item->length = 4096 and we are looking for logical = 8192, it is not part of item (item is [4096, 8191]). But the comparison is false and we think we have found the correct item, although we should be searing in the right subtree. This fixes some bugs I encountered. Signed-off-by: Marek Behun --- fs/btrfs/chunk-map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/chunk-map.c b/fs/btrfs/chunk-map.c index beb6a4bb92..0c9a659f8f 100644 --- a/fs/btrfs/chunk-map.c +++ b/fs/btrfs/chunk-map.c @@ -78,7 +78,7 @@ u64 btrfs_map_logical_to_physical(u64 logical) if (item->logical > logical) node = node->rb_left; - else if (logical > item->logical + item->length) + else if (logical >= item->logical + item->length) node = node->rb_right; else return item->physical + logical - item->logical;