From patchwork Thu Jan 19 17:40:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wedson Almeida Filho X-Patchwork-Id: 45881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp461129wrn; Thu, 19 Jan 2023 09:47:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXtn5Al5KebqioVPoOCqwuVhSxZuBGhKs7hhBfc/2AMl2ulQOPyPV7n2jCZNjsMaQzNt4xRG X-Received: by 2002:aa7:84c1:0:b0:58d:9b18:a36e with SMTP id x1-20020aa784c1000000b0058d9b18a36emr11923193pfn.31.1674150473730; Thu, 19 Jan 2023 09:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674150473; cv=none; d=google.com; s=arc-20160816; b=ulEDWuFy3827BiJewJfZZzzi2X8AY5CzMs3cGik8Hlzl3VBk6LON3TF9qf6s1Tscx9 +fJrBkAUKVrD/ndwqIgVGOCoT4ARLjb24OZiLWszbno9Smay9UFZ4zWGvEMkWPanmC3g 05AhORNefMrcyPTiFENwlzmw+E36PgbpwRk+4Dopwcf8CLAtLWb1ceuFfo3+0vMvsLMP kcC9bo4eSZphWbyKrPip6daum6bh1NzR1bGUWzPxUVixUILNph1c49KwhZsWU3SyLMr1 MuGQO7zKL3+l4xCJFdoz70uvgQpniErwuQBk7oeENbfSk9+Q/HLtv9sTffYOCCMd77td PRkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NO/tLxVBmWB1dJAexFMTC87LMSP1V8gc/xUgEhy6fvI=; b=Nv7K6gYhun/KL08u7nIGAB10q+xxUnFzgcE4hgmN2d6eg12r+TjTUdozhkXnE1LvFP +g/uRrz3szG6fjha0pO99V5N5ofuUL27itdclQarM8LfuPSkXD0pVAV60YHNmbDTOSSW GZqfyM8dVN4lt6OuGF80obXEosTTaZh7G7VAD7jhxVXFWKQQK4KTg8iPm/h1QYcwRyoD EWIRg/7pG8bBouUt6Mtz0RqnT4qYF5P8e9oHdXESRN4AvuQrefpGnrqJM7ecAqgLODiW NMdtG02481FoaPct6Uem+bAv2s7acZiJMh6W6mbNhPqJKlH2dur3LRL54vUPD393ItL3 HzkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="YBF/bv8H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y71-20020a62644a000000b0058a71b56a06si27772240pfb.130.2023.01.19.09.47.41; Thu, 19 Jan 2023 09:47:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="YBF/bv8H"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbjASRld (ORCPT + 99 others); Thu, 19 Jan 2023 12:41:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbjASRlW (ORCPT ); Thu, 19 Jan 2023 12:41:22 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0AE2798F9; Thu, 19 Jan 2023 09:41:08 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id v17so2297841oie.5; Thu, 19 Jan 2023 09:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NO/tLxVBmWB1dJAexFMTC87LMSP1V8gc/xUgEhy6fvI=; b=YBF/bv8HlX6jUtB0z4bb1xtYgg4EdDkd80BPaxQb8LIoAa6fmzgul3M6qSS5yRI8Cy fGIybIuQB5cT1uuCDHK3kr9/mIHcetjAftYjO88JzxaBX8e5VWpkkxPeu/gwtlmfwySs VUy4NLBcyyxcgsWBDrf78+meibyXGyuM4zzRsXhSpU5LrIWbeXMSjwbopFHonDvUeJag pYYIYKAD2jAqT2JzLQLfu5E1Iqk6teivVTyqrFiOhABiX1/yEc8lpFrYnFfj3TUGHiVK m88jKaFFsb/qKwQ0K9mlhfcJlgzHvGqzU1zR+vl0tVUIbsbu5f7FqlHMeSgZQqyTghny OCJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NO/tLxVBmWB1dJAexFMTC87LMSP1V8gc/xUgEhy6fvI=; b=ZZ0MyAIDcewrtMHq9udoGHkTzPVtU9QbsqSRRaKXKC+ExaalGiOo6EH1H1CFcowBcz 0x0kf/268TS7b+w/DY6P3Q+7so51m4lH4FdbYlPOLAd88ZNMtZdxKvAlPm+YMJE/hnT+ F4XSFWJPskaLw7tqCPvvP+TZ9OdMVW2B92BQwIz+YBYfDlTdTIp7EmSRWEAzz2Dc4ncO tFfh4/CgrRWWUBYHjAxXwt+vR8WKnURE5cZ/ElAXwPGXX/Md9hIyhngeJ2tW6NgE9g3x ose5x9e000yQ2e9G8iMqTcM504nkGEYEsbsfy1BoGJlnGyjmSAtgpAUsTEf4xnR+s3qx Cgzg== X-Gm-Message-State: AFqh2kq0s8BI8EsZ/DrzAH/0hC2vM+uQUUs1jKmEsYArmjiaxGx9rts5 FmBLlbdoPeOEyZyyAvtTlyVCXar7Lh729VYj X-Received: by 2002:aca:1710:0:b0:36e:b552:1ec3 with SMTP id j16-20020aca1710000000b0036eb5521ec3mr576626oii.38.1674150068191; Thu, 19 Jan 2023 09:41:08 -0800 (PST) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id i7-20020a056808054700b003631fe1810dsm10226906oig.47.2023.01.19.09.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 09:41:08 -0800 (PST) From: Wedson Almeida Filho To: rust-for-linux@vger.kernel.org Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?B?= =?utf-8?q?j=C3=B6rn_Roy_Baron?= , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [PATCH 4/5] rust: types: implement `ForeignOwnable` for the unit type Date: Thu, 19 Jan 2023 14:40:35 -0300 Message-Id: <20230119174036.64046-4-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119174036.64046-1-wedsonaf@gmail.com> References: <20230119174036.64046-1-wedsonaf@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755474006769420102?= X-GMAIL-MSGID: =?utf-8?q?1755474006769420102?= 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 --- rust/kernel/types.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index e037c262f23e..8f80cffbff59 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -85,6 +85,19 @@ impl ForeignOwnable for Box { } } +impl ForeignOwnable for () { + type Borrowed<'a> = (); + + fn into_foreign(self) -> *const core::ffi::c_void { + // We use 1 to be different from a null pointer. + 1usize as _ + } + + 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.