Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD8C7C05027 for ; Wed, 1 Feb 2023 09:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbjBAJ7O (ORCPT ); Wed, 1 Feb 2023 04:59:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbjBAJ7M (ORCPT ); Wed, 1 Feb 2023 04:59:12 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39EB532517 for ; Wed, 1 Feb 2023 01:59:11 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id me3so49764512ejb.7 for ; Wed, 01 Feb 2023 01:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20210112.gappssmtp.com; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=1SL9T3aYS6IFbexB1JuHREwm+6T3mP2MZTJ1gO4rfD8=; b=JLMtddu8szNLSJZLkW9ydSH98s7vymptf8mo+LrPH+7xSLZs7MWOHlZpVOuapE6pne +n0FVXyXbBJ372+UrAdqSAELmVDfie7c1OcvIRosaZF8sYjjygjN2gDMde5p8R5zrryt 8xMy5OAdjPU3KMPDvE2Nj7b9Fj8fyp/ikHGD79pOiVokqUsYifCjW+y7k5utHkUa8aRs 2mNgkBhnkOeI9K++AAaNYq/R8Hb9gJt4cvysEiuGfVEm+yNCwY8TeWjWBwqfB1mm2wvo xja/wZBAw7vSVUy3xClcaNHGHtAWoT4RTBBpifYT3kIL5RV1jzzwswDTd1Mmrt4ZLt/A tiCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:in-reply-to:date:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1SL9T3aYS6IFbexB1JuHREwm+6T3mP2MZTJ1gO4rfD8=; b=UWFXOpJ0kuHYqp/ZhPeWQEt4jof9CXLzDT6dmV+vWdIvrmW2SYDgktbChg3xVBqV+0 FLcn9yclTHcRh73hMhYoaHjvgUSNiT+34Ov5VUnJxyAY+ZljQGw66oJ9xUugfA9KV/Tb V23Zw0AtFw5e0wfjRfS6Wdo4O23ZEnRYDDn8GYCqK1xZPk1rKxcG5qHfMx4ctvIpsoIU n098DfxXbNorzSLygak3TM7YrRURG6kb6wFW3Rm1WaEhp9HS18OTKSkWaf2xlz9LExVo PMtNK5p1pf9f3nnU20oJ0NijULP3bSaubeSfrwncUv+5FoPzkKn9cFLlVoK2AYdYf6+S u9bg== X-Gm-Message-State: AO0yUKUdjOL5+GPL8/SRYWRgabhryKwJIvFL6EdFkcN7soZBMCMLI5jq 8CjFliYrwyOamfbj9/rGIgHr2g== X-Google-Smtp-Source: AK7set/Lz63IZfgfOEQQvMMBr8y1TLVqn7Fh8Arg6FsBJWPglWOg6nc4cnXcx/TRA7AxEmRn0d+Xdw== X-Received: by 2002:a17:906:d8ce:b0:87b:f7dd:792f with SMTP id re14-20020a170906d8ce00b0087bf7dd792fmr5638272ejb.8.1675245549817; Wed, 01 Feb 2023 01:59:09 -0800 (PST) Received: from localhost ([79.142.230.49]) by smtp.gmail.com with ESMTPSA id g9-20020a170906394900b00872a726783dsm9736926eje.217.2023.02.01.01.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 01:59:09 -0800 (PST) References: <20230130064404.744600-1-wedsonaf@gmail.com> <20230130064404.744600-4-wedsonaf@gmail.com> User-agent: mu4e 1.9.18; emacs 28.2.50 From: Andreas Hindborg To: Wedson Almeida Filho Cc: rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn?= Roy Baron , linux-kernel@vger.kernel.org, Vincenzo Palazzo , Andreas Hindborg Subject: Re: [PATCH v2 4/5] rust: types: implement `ForeignOwnable` for the unit type Date: Wed, 01 Feb 2023 10:58:27 +0100 In-reply-to: <20230130064404.744600-4-wedsonaf@gmail.com> Message-ID: <87h6w5k8pf.fsf@metaspace.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wedson Almeida Filho writes: > This allows us to use the unit type `()` when we have no object whose > ownership must be managed but one implementing the `ForeignOwnable` > trait is needed. > > Signed-off-by: Wedson Almeida Filho > Reviewed-by: Vincenzo Palazzo > --- Reviewed-by: Andreas Hindborg > v1 -> v2: use `NonNull::dangling` to generate pointer > > rust/kernel/types.rs | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs > index 411655eca3e9..9d0fdbc55843 100644 > --- a/rust/kernel/types.rs > +++ b/rust/kernel/types.rs > @@ -85,6 +85,18 @@ impl ForeignOwnable for Box { > } > } > > +impl ForeignOwnable for () { > + type Borrowed<'a> = (); > + > + fn into_foreign(self) -> *const core::ffi::c_void { > + core::ptr::NonNull::dangling().as_ptr() > + } > + > + unsafe fn borrow<'a>(_: *const core::ffi::c_void) -> Self::Borrowed<'a> {} > + > + unsafe fn from_foreign(_: *const core::ffi::c_void) -> Self {} > +} > + > /// Runs a cleanup function/closure when dropped. > /// > /// The [`ScopeGuard::dismiss`] function prevents the cleanup function from running.