Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp851627rwb; Fri, 23 Sep 2022 05:09:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DC8JgozHUvHe30BNHgZmcmIghkWUbCdSfIuLAbDL7Q0PCFgS9mwR1zSKwZYW0uY391dOb X-Received: by 2002:a17:906:9bd3:b0:778:c8e0:fcee with SMTP id de19-20020a1709069bd300b00778c8e0fceemr6785850ejc.275.1663934990318; Fri, 23 Sep 2022 05:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663934990; cv=none; d=google.com; s=arc-20160816; b=DitSb/qcSTTO961YfngMODsIGnpbDMmfigiSTgGUDN3mDEbrzvhbIv47+5SU5TPvj1 Q5b0Tv15mDbfuVqixsNraCPYiIXpnUh78VT/DRg2Z5RP5nFSz/accyySxVBhtXGhdnQ+ spR/qvbVBXRvxC1lPXlKWXpZXeb10kFhN8pvBUhEXrr9nzC007WvjI6i3gPxuaechkrk jQkyi9fkbbYi2z1VyKKP23ku0NTv3bk9sP1NmbVFoxgcXaByJOn+Qo1vPv7b3M6fT9wW 7Pid1eL4KxtoKjMpcfc8VwOsuWpBWs3ggzrmcvvsLlV02CWCec4AJk8rT6jME6K5msLU 4NYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=ZPjyD0/xt3seSELxX6T0Z8850lxbllz/WwfFXpyRRVE=; b=o9QLAd2trL6uR+Z+Hgj9nzueRKHIwodTvF03FOhs96aSVE663TnurJrObWSuybTR1j 7KR4pIWaCvKp5DEekJ8QtJTWBYmRdebLoUVqgOPp1jvPF+K5iIuW2Kg1KEn/YcnR3KLL 3vYl6fisEP0G9m+ho4YxMKGF6MTytIQaaKGQQpiEsS/3opkYolXYKn67F4mVe+JQLmdP aafiw8cwDUpf6YkShjsKs0wqZF55YZY7FDGE3cY2lSRrd1DyxdYwV9sMfhQ0NblPx4CH 5O9S60xcStc4AM1fC/pxR3Mf0FWvqrYAGPQ5PtGTfO/zWL+gVtKLtLB3rCrp6+Jj9V2z E25w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=3WQsmWHW; dkim=neutral (no key) header.i=@suse.cz header.b=Frwjz0Pd; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a50d592000000b0044ecd80f257si6785529edi.603.2022.09.23.05.09.19; Fri, 23 Sep 2022 05:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=3WQsmWHW; dkim=neutral (no key) header.i=@suse.cz header.b=Frwjz0Pd; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230359AbiIWLso (ORCPT + 99 others); Fri, 23 Sep 2022 07:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiIWLsn (ORCPT ); Fri, 23 Sep 2022 07:48:43 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED5613504C; Fri, 23 Sep 2022 04:48:42 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 7882B219AB; Fri, 23 Sep 2022 11:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1663933721; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZPjyD0/xt3seSELxX6T0Z8850lxbllz/WwfFXpyRRVE=; b=3WQsmWHWi98kHArxLDSeXFRquDbDCvwvEXdL6ZY6FGzw01ouFy+Q2ndzX0IeULWfM3ofUs 2FGllDhMidI9bcQsNiIx6tA/U4mx3ErUxaSsGhOas05LpogzWPXjQ1QZo8wBiysiviCq5W agahA403zfat5cYoVeB1AskuVYgJoGg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1663933721; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZPjyD0/xt3seSELxX6T0Z8850lxbllz/WwfFXpyRRVE=; b=Frwjz0PdM5zF+2ALhLDkWv3CN3NnGMsB4WcYTRwVo0ujr3IMYYqElkjXQoJsWfbZO7uyOh ty5L7ukhHEoMS1Ag== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 69F7013A00; Fri, 23 Sep 2022 11:48:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zYPUGRmdLWMxYgAAMHmgww (envelope-from ); Fri, 23 Sep 2022 11:48:41 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id F1472A0685; Fri, 23 Sep 2022 13:48:40 +0200 (CEST) Date: Fri, 23 Sep 2022 13:48:40 +0200 From: Jan Kara To: Zhihao Cheng Cc: jack@suse.com, tytso@mit.edu, brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com Subject: Re: [PATCH v2 2/3] quota: Replace all block number checking with helper function Message-ID: <20220923114840.npx52cadeofesp5i@quack3> References: <20220922130401.1792256-1-chengzhihao1@huawei.com> <20220922130401.1792256-3-chengzhihao1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220922130401.1792256-3-chengzhihao1@huawei.com> X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu 22-09-22 21:04:00, Zhihao Cheng wrote: > Cleanup all block checking places, replace them with helper function > do_check_range(). > > Signed-off-by: Zhihao Cheng > --- > fs/quota/quota_tree.c | 28 ++++++++++++---------------- > 1 file changed, 12 insertions(+), 16 deletions(-) Thanks for the fix! One comment below: > diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c > index f89186b6db1d..47711e739ddb 100644 > --- a/fs/quota/quota_tree.c > +++ b/fs/quota/quota_tree.c > @@ -71,11 +71,12 @@ static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf) > return ret; > } > > -static inline int do_check_range(struct super_block *sb, uint val, uint max_val) > +static inline int do_check_range(struct super_block *sb, uint val, > + uint min_val, uint max_val) > { > - if (val >= max_val) { > - quota_error(sb, "Getting block too big (%u >= %u)", > - val, max_val); > + if (val < min_val || val >= max_val) { > + quota_error(sb, "Getting block %u out of range %u-%u", > + val, min_val, max_val); > return -EUCLEAN; > } It is strange that do_check_range() checks min_val() with strict inequality and max_val with non-strict one. That's off-by-one problem waiting to happen when we forget about this detail. Probably make max_val non-inclusive as well (the parameter max_val suggests the passed value is the biggest valid one anyway). Honza -- Jan Kara SUSE Labs, CR