From nobody Tue Dec 26 03:57:54 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SzgwY2Trvz55TVg; Tue, 26 Dec 2023 03:58:05 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4SzgwX6c8jz4fw2; Tue, 26 Dec 2023 03:58:04 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.17.1/8.17.1) with ESMTP id 3BQ3vsO2091646; Tue, 26 Dec 2023 05:57:57 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 3BQ3vsO2091646 Received: (from kostik@localhost) by tom.home (8.17.1/8.17.1/Submit) id 3BQ3vsCk091645; Tue, 26 Dec 2023 05:57:54 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 26 Dec 2023 05:57:54 +0200 From: Konstantin Belousov To: Zhenlei Huang Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Subject: Re: git: 2a1d50fc12f6 - main - vfs_domount_update(): correct fsidcmp() usage Message-ID: References: <202312260136.3BQ1aOxq051977@gitrepo.freebsd.org> <72190C27-0D45-4300-BB78-719F5EB510E9@FreeBSD.org> <78061056-76D8-457C-A522-8CE62B481317@FreeBSD.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <78061056-76D8-457C-A522-8CE62B481317@FreeBSD.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on tom.home X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Spamd-Bar: ---- X-Rspamd-Queue-Id: 4SzgwX6c8jz4fw2 On Tue, Dec 26, 2023 at 11:31:38AM +0800, Zhenlei Huang wrote: > > > > On Dec 26, 2023, at 11:29 AM, Zhenlei Huang wrote: > > > > > > > >> On Dec 26, 2023, at 9:36 AM, Konstantin Belousov > wrote: > >> > >> The branch main has been updated by kib: > >> > >> URL: https://cgit.FreeBSD.org/src/commit/?id=2a1d50fc12f6e604da834fbaea961d412aae6e85 > >> > >> commit 2a1d50fc12f6e604da834fbaea961d412aae6e85 > >> Author: Andrew Gierth > > >> AuthorDate: 2023-12-24 12:04:21 +0000 > >> Commit: Konstantin Belousov > > >> CommitDate: 2023-12-26 01:35:46 +0000 > >> > >> vfs_domount_update(): correct fsidcmp() usage > >> > >> MFC after: 3 days > >> --- > >> sys/kern/vfs_mount.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c > >> index 8e54c832e9f1..331e4887c200 100644 > >> --- a/sys/kern/vfs_mount.c > >> +++ b/sys/kern/vfs_mount.c > >> @@ -1388,7 +1388,7 @@ vfs_domount_update( > >> error = EINVAL; > >> goto end; > >> } > >> - if (fsidcmp(&fsid_up, &mp->mnt_stat.f_fsid) != 0) { > >> + if (fsidcmp(fsid_up, &mp->mnt_stat.f_fsid) != 0) { > >> error = ENOENT; > >> goto end; > >> } > > > > > > The fsidcmp is currently defined as > ``` > #define fsidcmp(a, b) memcmp((a), (b), sizeof(fsid_t)) > ``` Yes, and the issue should be fixed by making it (inline) function, which automatically would type-check it args. > > > > > I guess we want to ensure ` typeof(a) == typeof(b) == fsid_t `, to prevent such kind of error in future. > > > > I see both gcc [1] and clang [2] have __builtin_types_compatible_p , so probably a good definition of fsidcmp should be > > > > ``` > > #define TYPEASSERT(v, t) \ > > _Static_assert(__builtin_types_compatible_p(typeof(v), t), "Requires type '" #t "'") > > > > #define fsidcmp(a, b) ({ \ > > TYPEASSERT((a), fsid_t *); \ > > TYPEASSERT((b), fsid_t *); \ > > memcmp((a), (b), sizeof(fsid_t)); \ > > }) > > ``` > > > > 1. https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html > > 2. https://clang.llvm.org/docs/LanguageExtensions.html > > Best regards, > > Zhenlei > > > >