Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1391800pxv; Fri, 2 Jul 2021 02:39:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUBS5ggVA3x05r7FsWPMGmTWfviwoJfp94MH78rUz9ycsjW6YL/6ac7LIbu+IklbkTu9LI X-Received: by 2002:a17:906:8149:: with SMTP id z9mr4338203ejw.547.1625218755271; Fri, 02 Jul 2021 02:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625218755; cv=none; d=google.com; s=arc-20160816; b=L/Qp+4y7d5ybog+s8MCd4Vu76DqGxdJM/QtRHfivaoIszVLe3YZJ2Isvi4ejYwQP30 7cH5Qxhk5cXng0tT36tnJa8lZM3oBbOCSJoZhLt4qO/zTFbJi/XwH1V95GdM2EoGxjqz tUSEGAhGgnQQJqGq89fxBhvllRYbQGZvbGOrYvhBLjA5it2rCMRvkCkT23p/w6sU0BjG MwMWJpAulZ7lMx/4zQE+aine3AOS5o4P1RmW/ehKIWWslqxkdHVdMQzvNw0/kNBNGsCU sid/irBRg1IbO4W2ryxNUtNqU1gyyMG6yJ9mCPavOVbDY6pjxz+f4agPtYdUNfT8UaMG +0SQ== 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; bh=tkJyKcy/IiS11XBHSsWE1sU1W22MTH0QdN6h7xIDEiw=; b=oGNnGkUoU+RD+zoRDed/wNm4EhmQX2WC25WOTu7XV3WkZ+qwC3Xdm/1VKyjtfzzIWp xwf0zx47UmiwHtzquNWQ0ekv5iZOQYSh+3nsFgm3SegNLqKB5lXCeEtV2agCJOVfFOos fgjp/cUImCq7+1HZmsnoO8x0OK17s8DebSX00OhS9YmG5mzJN85G2d/gDIi2p/SACl6O KQhNf7ePUjRmSc+uw5v5GmSMS3hiZuOCoAaU8UR2hP4vu8Fch8XXtVPs6zUBXertbA2+ rdEtMGYITq5+TH0nXiEkKIuA3JMaAB67xh/DpjvCD1eCRHddQbm4FNjTtIQUR0qnYknQ 4L6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="rOb9sQ/L"; 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 z21si1278675edb.572.2021.07.02.02.38.52; Fri, 02 Jul 2021 02:39:15 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="rOb9sQ/L"; 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 S231215AbhGBJhy (ORCPT + 99 others); Fri, 2 Jul 2021 05:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbhGBJhx (ORCPT ); Fri, 2 Jul 2021 05:37:53 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CD2C061762; Fri, 2 Jul 2021 02:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tkJyKcy/IiS11XBHSsWE1sU1W22MTH0QdN6h7xIDEiw=; b=rOb9sQ/LRIvaDOIhMJbEkKLisp 4gkSaYSOzuJoEWR5n8GUGO5dMvi6lV+VBr+20oS4D7mQfw3jGtDGPX8vze2UmcyNdJFxP1sBbo9XE k7fvR3xO7Y0MCBdRoTB6NfUImBd0ZYDFPlbYsnolauplqmGRnMris9sKm94lX1X0aNuxsE5N8Ir4p UGxNm2cCl7OOL243nYuFKXJ/1aCVt25a8M3aMOZRJ67PyKXWnd+0BW4iIyJ3VBJixkKWSIu+rxK07 EoKJELsYJtWTak9RNRxbLJrJvJsdX0un9g9Lfx2vUVIQFp64zX5+VrfhrHLaRbPTDQyUBUIa9O1CO xfLJWYVQ==; Received: from hch by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lzFZ1-007ZFU-97; Fri, 02 Jul 2021 09:34:40 +0000 Date: Fri, 2 Jul 2021 10:34:23 +0100 From: Christoph Hellwig To: Zhen Lei Cc: Christoph Hellwig , "Darrick J . Wong" , linux-xfs , linux-fsdevel , linux-kernel Subject: Re: [PATCH -next 1/1] iomap: Fix a false positive of UBSAN in iomap_seek_data() Message-ID: References: <20210702092109.2601-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210702092109.2601-1-thunder.leizhen@huawei.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We might as well just kill off the length variable while we're at it: 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;