Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp351438imp; Wed, 20 Feb 2019 01:11:29 -0800 (PST) X-Google-Smtp-Source: AHgI3IaZ5+Oe6qV0Ea9muA4wVin5fvpWX7MXnzXcJNOjMKo6LhYN0X8b8IzjKd3pV2ZlqHnhzfmW X-Received: by 2002:a17:902:7896:: with SMTP id q22mr36194366pll.280.1550653889277; Wed, 20 Feb 2019 01:11:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550653889; cv=none; d=google.com; s=arc-20160816; b=tP+hk3a+V5A/kiA99vLqLu2N5IiYdAGMC6FXlMphF/7FQrnLkW+D7kw4PxrlKQRXhr umyiHhujkRodhrQuWXeSU1I6SIzwsrZxLqMuX4iZchfwoC/286wU3IRXVkcBsNGBL7/o pJCE8cqSeiRUw6edLQBSGyEf60texc6ETLmCMJgnh5Ns5OK2X5vCdlAjYyBL8r6zl+UM VRmRdIns4fKfQ7kgyqhkKLaIlBo2pXLzHn4Kwps2sQ3OAAYz153DQLE3rt5nxIozVjtM mX6KIBOiZumV7BvyHc3Ut1wnVuiNJ15FdFpqLD/J6vdg/iTWQ2L3wYmXdEHpJ2qjSJFP ilFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=Zv0LNb03HkdNDYZLFTU23E2w0Eq/vv2/QLkBAJoAaCk=; b=XF2Bc7HWPKDaBrUHrMeaeUWKDBqlRboc2RgPlfoyGVDFV461jVZulbpq2zk124mHNv GmghwxABvfMpci06WZ+Lwc8uiOcefkTB+AmtslXUb2dp4u0tz3LdzcFbyPn7QsJNC3FM aX5Pb/on6qGq6vmGI/TUBI2jeXeYk9FLa81wrBA/7ui+5KkserTOkwctsQfpF4kzsSYd dOav02fciN4DB7SDyt3QOVgc3+AkKo6YCi8TyuFvk4pJzaEbvm3qxdFBPCTHSbMobGep 67BmFOqMC2Rbn0t2ciPc/wMwyBdyFmBcYvtl1DCS67427TqxOd+0P2ks3d+gqbKL6wMP 3bCg== 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 cv2si20818160plb.192.2019.02.20.01.11.14; Wed, 20 Feb 2019 01:11:29 -0800 (PST) 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 S1726671AbfBTJKd (ORCPT + 99 others); Wed, 20 Feb 2019 04:10:33 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3703 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725813AbfBTJKc (ORCPT ); Wed, 20 Feb 2019 04:10:32 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A008AE51137714A20048; Wed, 20 Feb 2019 17:10:29 +0800 (CST) Received: from [127.0.0.1] (10.177.31.96) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.408.0; Wed, 20 Feb 2019 17:10:24 +0800 Subject: Re: [PATCH -next] btrfs: Fix type conversion in btrfs_read_root_item To: Dan Carpenter References: <20190220030840.188854-1-yuehaibing@huawei.com> <20190220055621.GM17104@kadam> <20190220061009.GN17104@kadam> CC: Chris Mason , Josef Bacik , David Sterba , , , From: YueHaibing Message-ID: <916bcaa1-8e55-ed93-4d77-9a82d7443703@huawei.com> Date: Wed, 20 Feb 2019 17:10:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20190220061009.GN17104@kadam> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/2/20 14:10, Dan Carpenter wrote: > On Wed, Feb 20, 2019 at 08:58:43AM +0300, Dan Carpenter wrote: >> On Wed, Feb 20, 2019 at 03:08:40AM +0000, YueHaibing wrote: >>> btrfs_item_size_nr return value is u32, convert it to int may result >>> in truncation.Also read_extent_buffer expect a unsigned param, so >>> min_t should use type u32 to compare. >>> >>> Fixes: 8ea05e3a4262 ("Btrfs: introduce subvol uuids and times") >>> Signed-off-by: YueHaibing >>> --- >>> fs/btrfs/root-tree.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c >>> index 02d1a57af78b..893d12fbfda0 100644 >>> --- a/fs/btrfs/root-tree.c >>> +++ b/fs/btrfs/root-tree.c >>> @@ -21,12 +21,12 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot, >>> struct btrfs_root_item *item) >>> { >>> uuid_le uuid; >>> - int len; >>> + u32 len; >>> int need_reset = 0; >>> >>> len = btrfs_item_size_nr(eb, slot); >>> read_extent_buffer(eb, item, btrfs_item_ptr_offset(eb, slot), >>> - min_t(int, len, (int)sizeof(*item))); >> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >> Yeah, min_t() should normally cast to unsigned and the extra cast is >> silly. >> > > Btw, I shouldn't have had to dig through the patch to find the *real* > reason you wrote it. A better description would have said: > > There is a messy cast here: > > min_t(int, len, (int)sizeof(*item))); > > min_t() should normally cast to unsigned. It's not possible for > "len" to be negative, but if it were then then we definitely > wouldn't want to pass negatives to read_extent_buffer(). Also there > is an extra cast. > > This patch shouldn't affect runtime, it's just a clean up. Yes, This just a cleanup, Thanks! > > regards, > dan carpenter > > > . >