Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1149043ybt; Tue, 7 Jul 2020 08:50:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym90apo44l9T+nRBgNIiIkabv4j4G+I8tEO+n1z6ucet/3jhjhO0A4ZH70d0/ASKSxnlB1 X-Received: by 2002:a17:906:fa9b:: with SMTP id lt27mr46698535ejb.513.1594137013168; Tue, 07 Jul 2020 08:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594137013; cv=none; d=google.com; s=arc-20160816; b=LZe0XzS/wSlzHrYUy9KMGHMhVFiHMglPPohob8eHC1VLEshO/IXPJv5VPbvlU8Ld4L u6GVH9p5P42n6ZQxNxrseFE/Cgcm9ZpFvd5qVkt/8MR6r77+GBYRtiZgcWuO39A450Hp VisoAlvAtMrl+LzAoUn/cdzqffIN6tvx50ESf+8Fg1oT0iYnPkpHRxj4jmGk+Jl+R8e+ e3FFQHh1Qis6ymDay0IkOF7YEFex9jmTEd7lYR6cC21zZp+SrGziDThJcbsOrq2t79Sf U6HXRkODPQVuHTf1WV6UGaBKJj3zzaRj+HSyRM7cIL1Oj7ycLe+2uM2uWQvlTrmQtH4A nlKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:reply-to:message-id:subject:cc:to:from :date; bh=H5yUvMETvJ7teh/qm3WOfbls5f0xW/CrwiBnk5fPXh8=; b=lo8BmuA0muTiINji/ROyrvxCcQpqKEGiq3rlHJyOw8mQzk5ZyB4iYnJSdKZb5XaXHr Ca1/DTNExE+GMw4Q7L2VJJOwoiQ3lNy/N82WnaH15BGiHbGVQqrgzlmVvKMjceGFVlkE oY+OqIBD27Z9SZW+BZTnZB1FbQK2DX2h8pWPZPp9ovCivjpS8SKL0Jh0hYAmGs+LbIbR fhk0jXMZp71dG6cudTFAo81VYn3aK0WYJEqT3OajEnYf7BaEpua0UCZ3ENkjt1LwbRBz f4HpG5WqBsNYBzRf4Cjp168V+YBD7ho5Umz8UWact3gqT0bwZdriGTNFdZvlx4BWaAMo 32KA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bv8si6122802ejb.476.2020.07.07.08.49.50; Tue, 07 Jul 2020 08:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728801AbgGGPsR (ORCPT + 99 others); Tue, 7 Jul 2020 11:48:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:52846 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728133AbgGGPsQ (ORCPT ); Tue, 7 Jul 2020 11:48:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 13823AD19; Tue, 7 Jul 2020 15:48:15 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 10452DA818; Tue, 7 Jul 2020 17:47:56 +0200 (CEST) Date: Tue, 7 Jul 2020 17:47:55 +0200 From: David Sterba To: Nikolay Borisov Cc: trix@redhat.com, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] btfrs: initialize return of btrfs_extent_same Message-ID: <20200707154755.GB16141@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Nikolay Borisov , trix@redhat.com, clm@fb.com, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200705142058.28305-1-trix@redhat.com> <885129e4-d6d6-57d3-21d3-a83bd98c3994@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <885129e4-d6d6-57d3-21d3-a83bd98c3994@suse.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 05, 2020 at 05:48:17PM +0300, Nikolay Borisov wrote: > On 5.07.20 г. 17:20 ч., trix@redhat.com wrote: > > From: Tom Rix > > > > clang static analysis flags a garbage return > > > > fs/btrfs/reflink.c:611:2: warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn] > > return ret; > > ^~~~~~~~~~ > > ret will not be set when olen is 0 > > When olen is 0, this function does no work. > > > > So initialize ret to 0 > > > > Signed-off-by: Tom Rix > > Patch itself is good however, the bug cannot currently be triggered, due > to the following code in the sole caller (btrfs_remap_file_range): > > > > 15 if (ret < 0 || len == 0) > 14 goto out_unlock; > 13 > 12 if (remap_flags & REMAP_FILE_DEDUP) > 11 ret = btrfs_extent_same(src_inode, off, len, dst_inode, destoff); > 10 else > 9 ret = btrfs_clone_files(dst_file, src_file, off, > len, destoff); > > i.e len is guaranteed to be non-zero Yeah, for that reason I don't think we need to set the value inside btrfs_extent_same because the caller(s) do the sanity checks. There are VFS-level checks of the length wrt zero, eg. it won't even call to copy_file_range from vfs_copy_file_range. The user supplied length = 0 is interpreted as 'until the end of file' and is properly reclaculated in generic_remap_file_range_prep. This looks like clang checker is not able to follow the values accross function calls, even if the functions are static.