Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp559020pxb; Fri, 16 Apr 2021 12:09:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr0KtHQzQMuN443ilUox/rXZBGN3rZyiYmyzVGb4vffjhDPp5P0GgxlikZNotlNJJzVWFP X-Received: by 2002:a17:906:ecb0:: with SMTP id qh16mr10035472ejb.415.1618600174768; Fri, 16 Apr 2021 12:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618600174; cv=none; d=google.com; s=arc-20160816; b=oh1tTNNasXn0cI9tVca2OS7DbnMMNKICmT7LjQru9KVy5HgzWYrhNHSERW/C17K+Pv RqDTF+mqmyeIFuHxWFsggHc63MDeJw9Q0FLP4XQ253/4NU6LfA6ALrhSthfPpO5wp4bE 3jG9ENPlmeBshR7BqZIcHiqUpsFxBT3mg1G65NtNeibmw4Og1L91RFkXGx8NgQiKXzm8 nU5ZQQeUynjzpGekYYgBwTqyEBCbvaLkOqDnKb1OStK1rxoTWIDYkdZJx/q35DEqUDpz MDj+3vUcxna65wAcfaoEp1gwfDjw9CRY+gMuPMPghvc9QN01LFuO2s2aLQOaa8mnFpqk ywmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=/6x50vfbvJzdLZU3f1pj5acO9o8ChVa/HOtPfb2mKlw=; b=KytzP8QEgaJkvFUY61IkNBqAF/HzlMstFj0B2G6cEdHbSNGxDycpBua9qxAxjpoPju FsBAELCGh3YvWgy0YarLTGVxBbvL4eucl+LNNfIAnKV/n+T79o9b73vw1hlo+1XkHuFL whe6gbOFbZ0YcAXMGxW6z2qsrG5h89vbYezI1/GeigjvV0r8JvT1HSrGwV8pe4fK3QF+ TXev6DJNBZUG8hW7Qwbbsxg0Xr2BvC1Ds0i3vaewnxjh95yCLi7ObZ7EIYNDDzGmJr/E M7mCVYliQEuuwfpb06mZ+z7vY9iVubLoJiT3NHg2x2Fpselm14hXhqhVIEwVVUdNBwXr mTIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si1956189ejr.16.2021.04.16.12.09.11; Fri, 16 Apr 2021 12:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244343AbhDPSKr (ORCPT + 99 others); Fri, 16 Apr 2021 14:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237802AbhDPSKq (ORCPT ); Fri, 16 Apr 2021 14:10:46 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1451EC061574; Fri, 16 Apr 2021 11:10:21 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lXSul-005p9O-6e; Fri, 16 Apr 2021 18:09:59 +0000 Date: Fri, 16 Apr 2021 18:09:59 +0000 From: Al Viro To: Miguel Ojeda Cc: Linus Torvalds , Peter Zijlstra , Miguel Ojeda , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, Linux Kbuild mailing list , "open list:DOCUMENTATION" , Linux Kernel Mailing List , Alex Gaynor , Geoffrey Thomas , Finn Behrens , Adam Bratschi-Kaye , Wedson Almeida Filho , Michael Ellerman Subject: Re: [PATCH 04/13] Kbuild: Rust support Message-ID: References: <20210414184604.23473-1-ojeda@kernel.org> <20210414184604.23473-5-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 07:47:32PM +0200, Miguel Ojeda wrote: > On Fri, Apr 16, 2021 at 7:05 PM Linus Torvalds > wrote: > > > > Typical Rust error handling should match the regular kernel > > IS_ERR/ERR_PTR/PTR_ERR model fairly well, although the syntax is > > fairly different (and it's not limited to pointers). > > Yeah, exactly. We already have a `KernelResult` type which is a > `Result`, where `Error` is a wrapper for the usual kernel > int errors. > > So, for instance, a function that can either fail or return `Data` > would have a declaration like: > > pub fn foo() -> KernelResult > > A caller that needs to handle the error can use pattern matching or > one of the methods in `Result`. And if they only need to bubble the > error up, they can use the ? operator: > > pub fn bar() -> KernelResult { > let data = foo()?; > > // `data` is already a `Data` here, not a `KernelResult` > } Umm... A fairly common situation is foo() returns a pointer to struct foo instance or ERR_PTR() bar() returns a pointer to struct bar instance of ERR_PTR() bar() { struct foo *p; struct bar *res; .... // do some work, grab a mutex, etc. p = foo(); if (IS_ERR(p)) res = ERR_CAST(p); // (void *)p, internally; conceptually it's // ERR_PTR(PTR_ERR(p)); else res = blah(); .... // matching cleanup return res; } How well would ? operator fit that pattern? _If_ it's just a syntax sugar along the lines of "if argument matches Err(_), return Err(_)", the types shouldn't be an issue, but that might need some fun with releasing resources, etc. If it's something more elaborate... details, please.