Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1475149pxv; Fri, 2 Jul 2021 04:54:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweCdNm9g08eS8dRGtmZlfNl5kMqbUpA3Y08LPYx1LM2kyTnufG8MmVocw81rfobbDVIbRD X-Received: by 2002:a17:906:3057:: with SMTP id d23mr4915177ejd.131.1625226859827; Fri, 02 Jul 2021 04:54:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625226859; cv=none; d=google.com; s=arc-20160816; b=vn2pGOM37G4bSsdBSIS05CEG1ysrko9s9//GL3fMP/aiLyp88s0xol9yvbZPAG7DQX /TXZVVvoR6mnN330j1k8r71+vdFq9jiavQVe99KZJjpLmLRQkS5zA0SX7JYsql0Pa68B vtA6SMGhcadp/XAjqb2qaaFm6YnEIUJMK9MspjKUpeLh7Nd26RqCsnewORNtpCaTh4zO RS8nHshPWpirUh7tunBWEU9h9jUzEu5rbC5FKz+ZeuQFp7NFdtveQe5MQtQwh9adgdTy db0HTLzIy6kKVL9kneqA75Ejn4TB1HVdVBJbKABZEvRZfvmMYAd9AARxdGZd+iTW1Srr SGOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=NvJi/cEBE1eV5HLOgJrq3RH4DwByM19bFto25HMkkr4=; b=dzukVUnypzAYxSImRvaDBW7QBLv28K++0R5cbLQ5AlgEVKkxdzq55etVQEdbvu6j5i DBcRJH4HZJZa/5bkLaii/+u9/Co86YDbP4ZbFkffkzL6cIYeufZCNohL6/DhFGYH5iBA Ar6yhOpWE6T1PJXTxUuo5HA74NFY6GE5UkHhG3A84SwPX1/I9gVCwmWyFewVDZOiBLV+ CHC2bshQ8qUH7DMnBVt8lWMaYcz7xeZ97ISkRRqx3wED9f87gPTu8WPS2K9SDibvGnCQ b+1KvG79swRY5LnLb3CxDO7NJo6pdCyezixYXZPoZYjl7VZdXJH+3JgTA8N80S7C9lhN FPVw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd17si3147421ejc.732.2021.07.02.04.53.55; Fri, 02 Jul 2021 04:54:19 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232057AbhGBLxB (ORCPT + 99 others); Fri, 2 Jul 2021 07:53:01 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9446 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231936AbhGBLxB (ORCPT ); Fri, 2 Jul 2021 07:53:01 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GGYGZ6gZlzZmnq; Fri, 2 Jul 2021 19:47:18 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 2 Jul 2021 19:50:27 +0800 Received: from [127.0.0.1] (10.174.179.0) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 2 Jul 2021 19:50:26 +0800 Subject: Re: [PATCH -next 1/1] iomap: Fix a false positive of UBSAN in iomap_seek_data() To: Christoph Hellwig CC: "Darrick J . Wong" , linux-xfs , linux-fsdevel , linux-kernel References: <20210702092109.2601-1-thunder.leizhen@huawei.com> From: "Leizhen (ThunderTown)" Message-ID: <2ce02a7f-4b8b-5a86-13ee-097aff084f82@huawei.com> Date: Fri, 2 Jul 2021 19:50:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.0] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/7/2 17:34, Christoph Hellwig wrote: > We might as well just kill off the length variable while we're at it: Hi, Christoph: Maybe you need to write a separate patch. Because the patch I sent is to modify function iomap_seek_data(). I didn't look at the other functions. In fact, both iomap_seek_data() and iomap_seek_hole() need to be modified. The iomap_seek_data() may not be intuitive to delete the variable 'length'. I'm now analyzing if the "if (length <= 0)" statement in iomap_seek_data() is redundant (the condition is never true). > > > diff --git a/fs/iomap/seek.c b/fs/iomap/seek.c > index dab1b02eba5b7f..942e354e9e13e6 100644 > --- a/fs/iomap/seek.c > +++ b/fs/iomap/seek.c > @@ -35,23 +35,21 @@ loff_t > iomap_seek_hole(struct inode *inode, loff_t offset, const struct iomap_ops *ops) > { > loff_t size = i_size_read(inode); > - loff_t length = size - offset; > loff_t ret; > > /* Nothing to be found before or beyond the end of the file. */ > if (offset < 0 || offset >= size) > return -ENXIO; > > - while (length > 0) { > - ret = iomap_apply(inode, offset, length, IOMAP_REPORT, ops, > - &offset, iomap_seek_hole_actor); > + while (offset < size) { > + ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT, > + ops, &offset, iomap_seek_hole_actor); > if (ret < 0) > return ret; > if (ret == 0) > break; > > offset += ret; > - length -= ret; > } > > return offset; > > . >