Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3130084ybn; Fri, 27 Sep 2019 01:21:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqy57HqCGOxoWaaHXfpY190cX/nEb2tIDPVzrIHJOu9xLFNROld6tUzv8NeM2OP1/ZZegaQS X-Received: by 2002:a17:906:5295:: with SMTP id c21mr6738212ejm.80.1569572501290; Fri, 27 Sep 2019 01:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569572501; cv=none; d=google.com; s=arc-20160816; b=CWy7BKMpUYSS11u/dKIq+7FRH1x4p40bR2JOUW1I28iPNL5H+fDQT/pvg0D/JRATCE 4EWXyWJTgigE7lWZRMtd+k0kP/0YPz1Lan7XrbkrK0J9InB1b81ACjIDiw+leUkjqbpZ xYXsWCIO9fn66woUOKxK1+bp902HyGZWtDwX/Qmel3cP+09tvede4d7ERwAipvHncW3+ TA7B1Fwhv88y+3m+UlwY5Z5yX4fv6DpyuTZM2Ifv1fTXdFG21xCcPrG2N/lCqpU7iD/+ Fs/B24AhiWWbJEAiJrZN7ZP59WN5dzX9CJZouJSIx99GrjDQgA+SyKyEYp+68JU+mHhy /dqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=XRMo1fzkVQZkK0A4fCFvqCnFsRj61mDAGVK5Rxv81HE=; b=cyZtfx6xTtVJ9f+LHkBQ+PgqjjUZIoz00eKO7UpLL0hmD1In42iwWStAEJUI4CCUQP 3I1PEumaFnw5s3kbH7BmeMa5lX2oI9k2pObmIzIl+XhgpzPQGXKMzxMq40XDBzJzZocn HZnM1UbEkQ1Hi33RpoGtcVr8WSJPJp2K0/Tf38LqwFHG+m66OjxzvJqhdiEARkFXvHR5 p2PnhB8yT4WOEiDUvrnwTAXZV9oUQQUjQMbqPfzrX/3sjfNPAWWPwk3TEjOLMqVU6zHU k5TODozn2K5e7tSVMB72ysT1NXQvAQreHNBegPvFeWQwjdbDJWFeWUiUfFe/Lp05l1IM UwTg== 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 g3si1146209edj.220.2019.09.27.01.21.16; Fri, 27 Sep 2019 01:21:41 -0700 (PDT) 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 S1726975AbfI0IUb (ORCPT + 99 others); Fri, 27 Sep 2019 04:20:31 -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