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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 735F0C4361B for ; Thu, 17 Dec 2020 12:32:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FD382339E for ; Thu, 17 Dec 2020 12:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727119AbgLQMbz (ORCPT ); Thu, 17 Dec 2020 07:31:55 -0500 Received: from mx2.suse.de ([195.135.220.15]:49716 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726999AbgLQMbz (ORCPT ); Thu, 17 Dec 2020 07:31:55 -0500 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 D6C4AACF9; Thu, 17 Dec 2020 12:31:13 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id EB900DA83A; Thu, 17 Dec 2020 13:29:33 +0100 (CET) Date: Thu, 17 Dec 2020 13:29:33 +0100 From: David Sterba To: Qu Wenruo Cc: Nikolay Borisov , linux-btrfs@vger.kernel.org Subject: Re: [PATCH 2/4] btrfs: inode: remove variable shadowing in btrfs_invalidatepage() Message-ID: <20201217122933.GM6430@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , Nikolay Borisov , linux-btrfs@vger.kernel.org References: <20201217045737.48100-1-wqu@suse.com> <20201217045737.48100-3-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Thu, Dec 17, 2020 at 02:13:37PM +0800, Qu Wenruo wrote: > > > On 2020/12/17 下午1:59, Nikolay Borisov wrote: > > > > > > On 17.12.20 г. 7:55 ч., Nikolay Borisov wrote: > >> > >> > >> On 17.12.20 г. 6:57 ч., Qu Wenruo wrote: > >>> In btrfs_invalidatepage() we re-declare @tree variable as > >>> btrfs_ordered_inode_tree. > >>> > >>> Remove such variable shadowing which can be very confusing. > >> > >> You can't do that, because lock_extent_bits expects extent_io_tree ! > >> > > > > Ok, nvm, you just factored the var at the beginning of the functions. > > OTOH since the ordered tree is used just for lock/unlock why not do > > spin_(un)lock(&inode->ordered_tree->lock); > > > Oh, that indeed looks better and since Su is also complaining about the > declaration at the beginning of the function, I guess that's the better > way to go. The preferred style is to declare variables in the closest scope, so there's not a huge blob of declarations that are randomly used inside nested blocks. It's more like a recommendation, eg. when the function is short and there are a few variables used inside a for/while.