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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 57330C4360C for ; Fri, 27 Sep 2019 08:20:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AD75217D9 for ; Fri, 27 Sep 2019 08:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbfI0IUc (ORCPT ); Fri, 27 Sep 2019 04:20:32 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58440 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbfI0IUb (ORCPT ); Fri, 27 Sep 2019 04:20:31 -0400 Received: from [65.39.69.237] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iDlU9-0001TO-Vj; Fri, 27 Sep 2019 08:20:18 +0000 Date: Fri, 27 Sep 2019 10:20:17 +0200 From: Christian Brauner To: Aleksa Sarai Cc: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , 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: <20190927082016.jsis76s26uverj5r@wittgenstein> References: <20190925230332.18690-1-cyphar@cyphar.com> <20190925230332.18690-2-cyphar@cyphar.com> <20190925232139.45sbhj34fj7yvxer@wittgenstein> <20190927010736.gy3vvvkjhwlybosj@yavin.dot.cyphar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190927010736.gy3vvvkjhwlybosj@yavin.dot.cyphar.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 27, 2019 at 11:07:36AM +1000, Aleksa Sarai wrote: > 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 = (uintptr_t) from % sizeof(unsigned long); > > > + > > > + if (unlikely(!size)) > > > + return true; > > > > You're returning "true" and another implicit boolean with (val == 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) [ยง7.18]. So this is perfectly well-defined. > If you declare a function as returning an int, return ints and don't mix returning ints and "proper" C boolean types. This: static int foo() { if (bla) return true; return -1; } is just messy. > > Personally, I think it's more readable to have: > > if (unlikely(size == 0)) > return true; > /* ... */ > return (val == 0); > > compared to: > > if (unlikely(size == 0)) > return 1; > /* ... */ > return val ? 0 : 1; Just do: if (unlikely(size == 0)) return 1; /* ... */ return (val == 0); You don't need to change the last return. Also, as I said in a previous mail: Please wait for rc1 (that's just two days) to be out so you can base your patchset on that as there are changes in mainline that cause a merge conflict with your changes. Thanks! Christian