Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp250968ybx; Fri, 1 Nov 2019 02:58:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwknIBGoIch/6dqTiYkFdcuSc/qLa0eH0XC81d7frEG5o8t4RpQ/Txa/oPwGJxJrY9F8si0 X-Received: by 2002:aa7:cb41:: with SMTP id w1mr11629105edt.18.1572602286257; Fri, 01 Nov 2019 02:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572602286; cv=none; d=google.com; s=arc-20160816; b=wH1iAw9Usv7i0PoA3tUUGZ6vb+rOt81Npy9mxjzbTUIbu4HYXIba9i4OGlAfVBmaU3 XnV/3xozisVzhWSx7YgS70LArdJTvU27Hr45ObQfoUm8PG2oFscpo50Fk/8lDVsiUkw/ J3ONZQVINbt6aYyAoqh8MJI70vfVbbZf4z0ZWzlqapnXVv/nUt53uR/TXYhZk7LMg2f4 16j3JlIM6jhyhZ4J2Ain7QbEc5TUqZ8y219TLIDjYagFg+HiEEJj3kxPCJUYy8O9cRLH wX01uAd0rHSEUQ0+spCnscri8h0TvL8NG507ND2Fv+4UKpghWPJ3PIce5aHmF1wV/7qS pEHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=E4xg7o4BZYmggCqKdus3rRqvJ+Lb2cY/P0qQmQglha4=; b=hbu7Vu5vi9HDMsmZJEaQhq1ywkceSw3s/YoGjpRel6hgHrOQV1jnmb9GG3IqElh/As 6itVux/+q4Yg6KjIEtvLDoWmFgdU3GoAWjoA4vriX5ncmR0Bv/ju5XWkiz6H4XJcALQA CR/CZiVyTm1LYj8J7HpjiMLy/d7Oo2Hc1rvkt0tIihsLVUXol2woQcluhQw4YZlcd4y2 fCxHD9l2k/BtPbCgZWTuM5+uHFY1M9RI/pZ/w8gr9aYoR+fLjlWU9iblsQ4HjjIV/1JG TFbLJ5u1ZyEb/RzDYE61PN4isL4p9JoW0KeXs44axEu52bUs1B8+P+kc4wFW9Y8dDm19 lhEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u59si7085273edc.193.2019.11.01.02.57.42; Fri, 01 Nov 2019 02:58:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729074AbfKAJyJ (ORCPT + 99 others); Fri, 1 Nov 2019 05:54:09 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5247 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726771AbfKAJyC (ORCPT ); Fri, 1 Nov 2019 05:54:02 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 60DFD2FAC0E85D290225; Fri, 1 Nov 2019 17:53:59 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Fri, 1 Nov 2019 17:53:48 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH 1/3] f2fs: clean up check condition for writting beyond EOF Date: Fri, 1 Nov 2019 17:53:22 +0800 Message-ID: <20191101095324.9902-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clean up with below codes suggested by Eric: __write_data_page() unsigned nr_pages = DIV_ROUND_UP(i_size, PAGE_SIZE); /* * If the offset is out-of-range of file size, * this page does not have to be written to disk. */ if (page->index >= nr_pages) goto out; Signed-off-by: Chao Yu --- fs/f2fs/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index ba3bcf4c7889..ca7161e38d1f 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2204,6 +2204,7 @@ static int __write_data_page(struct page *page, bool *submitted, const pgoff_t end_index = ((unsigned long long) i_size) >> PAGE_SHIFT; loff_t psize = (page->index + 1) << PAGE_SHIFT; + unsigned nr_pages = DIV_ROUND_UP(i_size, PAGE_SIZE); unsigned offset = 0; bool need_balance_fs = false; int err = 0; @@ -2248,8 +2249,7 @@ static int __write_data_page(struct page *page, bool *submitted, * If the offset is out-of-range of file size, * this page does not have to be written to disk. */ - offset = i_size & (PAGE_SIZE - 1); - if ((page->index >= end_index + 1) || !offset) + if (page->index >= nr_pages) goto out; zero_user_segment(page, offset, PAGE_SIZE); -- 2.18.0.rc1