From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2120BC43381 for ; Fri, 22 Feb 2019 13:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4CDB207E0 for ; Fri, 22 Feb 2019 13:02:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbfBVNCv (ORCPT ); Fri, 22 Feb 2019 08:02:51 -0500 Received: from mx2.suse.de ([195.135.220.15]:43882 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726199AbfBVNCu (ORCPT ); Fri, 22 Feb 2019 08:02:50 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5146CAEF8; Fri, 22 Feb 2019 13:02:48 +0000 (UTC) Subject: Re: [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer() To: Nikolay Borisov , linux-btrfs@vger.kernel.org Cc: dan.carpenter@oracle.com References: <20190222101645.4403-1-wqu@suse.com> From: Qu Wenruo Openpgp: preference=signencrypt Autocrypt: addr=wqu@suse.de; prefer-encrypt=mutual; keydata= mQENBFnVga8BCACyhFP3ExcTIuB73jDIBA/vSoYcTyysFQzPvez64TUSCv1SgXEByR7fju3o 8RfaWuHCnkkea5luuTZMqfgTXrun2dqNVYDNOV6RIVrc4YuG20yhC1epnV55fJCThqij0MRL 1NxPKXIlEd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BgB CAAmFiEELd9y5aWlW6idqkLhwj2R86El/qgFAlnVga8CGwwFCQPCZwAACgkQwj2R86El/qgN 8Qf+M0vM2Idwm5txZZSs+/kSgcPxEwYmxUinnUJGyc0ZWYQXPl0cBetZon9El0naijGzNWvf HxIPB+ZFehk6Otgc78p1a3/xck/s1myFRLrmbbTJNoFiyL25ljcq0J8z5Zp4yuABL2RiLdaZ Pt/jfwjBHwGR+QKp6dD2qMrUWf9b7TFzYDMZXzZ2/eoIgtyjEelNBPrIgOFe24iKMjaGjd97 fJuRcBMHdhUAxvXQF1oRtd83JvYJ5OtwTd8MgkEfl+fo7HwWkuHbzc70L4fFKv2BowqFdaHy mId1ijGPGr46tuZ5a4cw/zbaPYx6fJ4sK9tSv/6V1QPNUdqml6hm6pfs6A== Message-ID: Date: Fri, 22 Feb 2019 21:02:14 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="eRNpon27ybcalqfgYpEdIjJcv06LEyHPb" Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --eRNpon27ybcalqfgYpEdIjJcv06LEyHPb Content-Type: multipart/mixed; boundary="Mhjit2FOh6a4GcJQQ9yH8wdeU1ylPiwU7"; protected-headers="v1" From: Qu Wenruo To: Nikolay Borisov , linux-btrfs@vger.kernel.org Cc: dan.carpenter@oracle.com Message-ID: Subject: Re: [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer() References: <20190222101645.4403-1-wqu@suse.com> In-Reply-To: --Mhjit2FOh6a4GcJQQ9yH8wdeU1ylPiwU7 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 2019/2/22 =E4=B8=8B=E5=8D=888:54, Nikolay Borisov wrote: >=20 >=20 > On 22.02.19 =D0=B3. 12:16 =D1=87., Qu Wenruo wrote: >> This patchset can be fetched from github: >> https://github.com/adam900710/linux/tree/cleanup_alloc_extent_buffer >> Which is based on v5.0-rc7 >> >> There are 5 extent buffer alloc functions in btrfs: >> __alloc_extent_buffer(); >> alloc_extent_buffer(); >> __alloc_dummy_extent_buffer(); >> alloc_dummy_extent_buffer(); >> alloc_test_extent_buffer(); >> >> However their return value is not unified for failure mode: >> __alloc_extent_buffer() Never fail >> alloc_extent_buffer() PTR_ERR() >> __alloc_dummy_extent_buffer() NULL >=20 > This function can never return NULL, if __alloc_extent_buffer cannot > fail then the only error this function returns is ERR_PTR(ENOMEM); Nope. for (i =3D 0; i < num_pages; i++) { eb->pages[i] =3D alloc_page(GFP_NOFS); if (!eb->pages[i]) goto err; <<< Page alloc failure here } =2E.. err: for (; i > 0; i--) __free_page(eb->pages[i - 1]); __free_extent_buffer(eb); return NULL; << We got NULL. } For __alloc_dummy_extent_buffer, that's the only failure case. And I'm interested how did you get the PTR_ERR() case? >=20 >> alloc_dummy_extent_buffer() NULL > Same thing applies to this function Nope. >=20 >> alloc_test_extent_buffer() NULL >=20 > Same thing for this function, if we return exists then we must have > found it by find_extent_buffer hence it cannot be null. Otherwise we > return eb as allocated from alloc_dummy_extent_buffer. So how can null > be returned? And nope. >=20 > To me it really seems none of the function could return a NULL value, n= o? Your misunderstand of __alloc_dummy_extent_buffer() makes the call chain all wrong. Thanks, Qu >=20 >> >> This causes some wrapper function to have 2 failure modes, like >> btrfs_find_create_tree_block() can return NULL or PTR_ERR(-ENOMEM) for= >> its failure. >> >> This inconsistent behavior is making static checker and reader crazy. >> >> This patchset will unify the failure more of above 5 functions to >> PTR_ERR(). >> >> Qu Wenruo (5): >> btrfs: extent_io: Add comment about the return value of >> alloc_extent_buffer() >> btrfs: extent_io: Unify the return value of __alloc_extent_buffer() >> with alloc_extent_buffer() >> btrfs: extent_io: Unify the return value of >> alloc_dummy_extent_buffer() with alloc_extent_buffer() >> btrfs: extent_io: Unify the return value of alloc_test_extent_buffer= () >> with alloc_extent_buffer() >> btrfs: extent_io: Unify the return value of >> btrfs_clone_extent_buffer() with alloc_extent_buffer() >> >> fs/btrfs/backref.c | 8 ++-- >> fs/btrfs/ctree.c | 16 ++++---- >> fs/btrfs/extent_io.c | 56 +++++++++++++++++--------= - >> fs/btrfs/qgroup.c | 5 ++- >> fs/btrfs/tests/extent-buffer-tests.c | 6 ++- >> fs/btrfs/tests/extent-io-tests.c | 4 +- >> fs/btrfs/tests/free-space-tree-tests.c | 3 +- >> fs/btrfs/tests/inode-tests.c | 6 ++- >> fs/btrfs/tests/qgroup-tests.c | 3 +- >> 9 files changed, 68 insertions(+), 39 deletions(-) >> >=20 --Mhjit2FOh6a4GcJQQ9yH8wdeU1ylPiwU7-- --eRNpon27ybcalqfgYpEdIjJcv06LEyHPb Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEELd9y5aWlW6idqkLhwj2R86El/qgFAlxv8tYACgkQwj2R86El /qgx+Af9FPf+D3/KL2yxcwaqsJzkWeVCnrfnif+UahpGY4U7frSm+7i1xn8/0zxQ /UUIf/+cgfRUEZddCt4jlySFAAbDsDM8aXTMEsQJc7vUgpWWsiS5VNOA588vO2LX haM/9Gsj2pqG49eHPM9KvWSMKjCB2Qk+Lf3k3pctLP/LlQc34/gRDAobaB1Ic9Wq IOr9ovqqBGuxVzGIzIJwTYBXGWIQfbayL+gR7os5SPyi7V2qB8kDoLI9RNwOOKNf EAKUsdofaDlFMdJlYrkmn87K8VGl3pqrc+FBM+6nLxdPLUM3Odxwet4ahL/gCDb9 ea7TwQRyEANy6Z1RyJ8Y2lFEWY9pgw== =r5D6 -----END PGP SIGNATURE----- --eRNpon27ybcalqfgYpEdIjJcv06LEyHPb--