From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 174A0C43214 for ; Thu, 19 Aug 2021 08:05:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0261A6113E for ; Thu, 19 Aug 2021 08:05:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237121AbhHSIF7 (ORCPT ); Thu, 19 Aug 2021 04:05:59 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:52998 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237366AbhHSIFf (ORCPT ); Thu, 19 Aug 2021 04:05:35 -0400 Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C97CC220AB; Thu, 19 Aug 2021 08:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1629360298; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lbt5bilk+mkKsR6yUASoh7dcllM614kqXGh7Nu0wzoo=; b=HnGjtNie99tOrT/G6xAkAinVZGXKrEkd3TtISCnDr7ZK/kY3wJGQe0R9Zq9F+r5ZOLjVz2 ebfGVvrwn220PiBhCmnWbS3zyThRMgeuk66KP7NKpeqJXkqQ5vRjgpHVFqzd9UJanmCUdq br/xb1p6xlOVR0VYVzESkpdpD1K4Szg= Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 9B99A136DD; Thu, 19 Aug 2021 08:04:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id rc2QIqoQHmE8EgAAGKfGzw (envelope-from ); Thu, 19 Aug 2021 08:04:58 +0000 Subject: Re: [PATCH] btrfs: reflink: Assure length != 0 in btrfs_extent_same() To: Sidong Yang , linux-btrfs References: <20210818160815.1820-1-realwakka@gmail.com> From: Nikolay Borisov Message-ID: Date: Thu, 19 Aug 2021 11:04:58 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210818160815.1820-1-realwakka@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On 18.08.21 г. 19:08, Sidong Yang wrote: > btrfs_extent_same() cannot be called with zero length. Because when > length is zero, it would be filtered by condition in > btrfs_remap_file_range(). But if this function is used in other case in > future, it can make ret as uninitialized. > > Signed-off-by: Sidong Yang This is not sufficient, with the assert compiled out the error would still be in place. It seem that it is sufficient to initialize ret to some non-arbitrary value i.e -EINVAL ? > --- > fs/btrfs/reflink.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c > index 9b0814318e72..69eb50f2f0b4 100644 > --- a/fs/btrfs/reflink.c > +++ b/fs/btrfs/reflink.c > @@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen, > u64 i, tail_len, chunk_count; > struct btrfs_root *root_dst = BTRFS_I(dst)->root; > > + ASSERT(olen); > spin_lock(&root_dst->root_item_lock); > if (root_dst->send_in_progress) { > btrfs_warn_rl(root_dst->fs_info, >