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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 256D2C4360C for ; Fri, 27 Sep 2019 01:08:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF248207FF for ; Fri, 27 Sep 2019 01:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfI0BH5 (ORCPT ); Thu, 26 Sep 2019 21:07:57 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:62680 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbfI0BH5 (ORCPT ); Thu, 26 Sep 2019 21:07:57 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 392C0A16F2; Fri, 27 Sep 2019 03:07:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id IOcJDIfveQSW; Fri, 27 Sep 2019 03:07:49 +0200 (CEST) Date: Fri, 27 Sep 2019 11:07:36 +1000 From: Aleksa Sarai To: Christian Brauner Cc: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Rasmus Villemoes , Al Viro , Linus Torvalds , libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/4] lib: introduce copy_struct_from_user() helper Message-ID: <20190927010736.gy3vvvkjhwlybosj@yavin.dot.cyphar.com> References: <20190925230332.18690-1-cyphar@cyphar.com> <20190925230332.18690-2-cyphar@cyphar.com> <20190925232139.45sbhj34fj7yvxer@wittgenstein> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ningxfpyii3awxw6" Content-Disposition: inline In-Reply-To: <20190925232139.45sbhj34fj7yvxer@wittgenstein> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ningxfpyii3awxw6 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-09-26, Christian Brauner wrote: > On Thu, Sep 26, 2019 at 01:03:29AM +0200, Aleksa Sarai wrote: > > +int is_zeroed_user(const void __user *from, size_t size) > > +{ > > + unsigned long val; > > + uintptr_t align =3D (uintptr_t) from % sizeof(unsigned long); > > + > > + if (unlikely(!size)) > > + return true; >=20 > You're returning "true" and another implicit boolean with (val =3D=3D 0) > down below but -EFAULT in other places. But that function is int > is_zeroed_user() Would probably be good if you either switch to bool > is_zeroed_user() as the name suggests or rename the function and have > it return an int everywhere. I just checked, and in C11 (and presumably in older specs) it is guaranteed that "true" and "false" from have the values 1 and 0 (respectively) [=A77.18]. So this is perfectly well-defined. Personally, I think it's more readable to have: if (unlikely(size =3D=3D 0)) return true; /* ... */ return (val =3D=3D 0); compared to: if (unlikely(size =3D=3D 0)) return 1; /* ... */ return val ? 0 : 1; But I will change the function name (to check_zeroed_user) to make it clearer that it isn't returning a boolean and that you need to check for negative returns. --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --ningxfpyii3awxw6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSxZm6dtfE8gxLLfYqdlLljIbnQEgUCXY1g0wAKCRCdlLljIbnQ EmniAP96l+2UHf1KZUsjmkF+ni1i3z9S8CcAMfeKjnFvKTEOmAD+Kamb7z8aEEP6 x2hEUZydsZf2ME41Ml2G9Z9uGlezWgM= =zhm8 -----END PGP SIGNATURE----- --ningxfpyii3awxw6--