From patchwork Mon Jan 30 06:44:03 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: 50151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2038781wrn; Sun, 29 Jan 2023 22:47:30 -0800 (PST) X-Google-Smtp-Source: AK7set+dQ5bZiwQz+33t55s8AfBW9MTTgarc9aX3e3BYKL9SJCoX95HoHPtnRxORMp3mSWgPxV2N X-Received: by 2002:a17:907:2bc2:b0:885:fcbd:40d3 with SMTP id gv2-20020a1709072bc200b00885fcbd40d3mr5328222ejc.8.1675061250484; Sun, 29 Jan 2023 22:47:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675061250; cv=none; d=google.com; s=arc-20160816; b=KEHaqXSWEfPEPb+bz2gfErLN8Gqn6Jlgh5T5u3A8Z92PKKK/zeyspO6Rr4dbdhm8ou FEmvol3dfmy9s4bsttltSCmLgs40wB+f3WWwjaca9348qKz5MQLlblMQR+zGwd9+djc6 8lRZR/eXrN94GXfncFfIHXKYADUeV890y1bme7Uyf7vc+nLgXlvySh6AbzqBxMynX/EV CvH5Xf9NZJjHyiM3rmnCCCi17dySHfj8TdSjIDAiqwJuOhCGWESEj+sFmyngfmDdlaeF dc+IwOkf9LZ9T+zwNs05n695nyH/L28VD+zIMBL86o30yHLxTdQzh2jd78ElyRsya323 cLQg== 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=1+8DLLeJL2vbcZ/1sx6aN3cI3SB5furv18W3lUJcflM=; b=0CFBrlW8wu0uHXU4QLw+/RX9t2BL8Z8EodCCMPk0nySWa0edOIepyYaUXAuq6cvQ9u PPD/cu6Od0VFah77XUqdJpoVHvelIYQvfU+yXp551K9vU9/c4CjEQJJBoh4/isPmDBCl f3N7Kt5h1NyqAnzQdyhqe+a1yrRRGUjmmMdNVvLdhdrhqw+VYueBbJ7B/F8YQ1H4+jFl eproPjqE9D/4/ItLzWeaAag2rU5dl3AJ7lsnC+Jg877Phsiq6L8b0XvVCPr9Ns/+4SlZ FPIC5vd752xqmbKVD0H3+u3NwCWEH3FBT4No8Grss/yy9XcJTM6ZPLVmX4WMAwbcEEdH sfYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TfF3Ypmn; 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 19-20020a17090602d300b007c0b56b90f5si12431582ejk.307.2023.01.29.22.47.07; Sun, 29 Jan 2023 22:47:30 -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=TfF3Ypmn; 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 S235859AbjA3GpI (ORCPT + 99 others); Mon, 30 Jan 2023 01:45:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235835AbjA3Gop (ORCPT ); Mon, 30 Jan 2023 01:44:45 -0500 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D737013DF8; Sun, 29 Jan 2023 22:44:40 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id dt8so6166611oib.0; Sun, 29 Jan 2023 22:44:40 -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=1+8DLLeJL2vbcZ/1sx6aN3cI3SB5furv18W3lUJcflM=; b=TfF3Ypmncs4V09HuumYfpFm2C0xZDaLKRAETSnCb/bJZmvUNrMXwDR1J/l2c+VxFAJ VBfW1vtGgiOBjxi4NWhvcIR2B52khFq6DOz4uCVsmIcUXJ7izYbDofHb5RnENJhF4ogR gbq94kf5XPsGkRU5sDtpAyCRrtfy8/YVeNt2nWXhlU4VbBJNiwVTDNYoP/4G+DNpIpVF W3MIZA7jAKnuiMoxDcbA7uG/Lm7wFs1nBXQssgXV+OcpwhasNu5LuEhF+GKI9TI4TnaL 08Uv8P2uQdUAqTDOPv9MFFKhegpm6H0ByTzb0Ng4PySW/1r8wclHhhpNtjd5oMBhxOkU qsFg== 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=1+8DLLeJL2vbcZ/1sx6aN3cI3SB5furv18W3lUJcflM=; b=SGfIV6y+/L8vmFoH2NGTdzpyL0LpeczeUFcTMIX3MJG8HlCgNlaZMzIDYP5kLOowj7 14G4MpXw5QH9f/PGw2U0fPHlOjPbfMcaeIltCmlqI6Dam+3ystos0DGPWPEudWh3DXoy OQFiQ/tZ4f+X5tEKW0hkK3yHUyAFr+kJydGvwL3Cup/76OyGZC1BEPnnbCvFc/QutqK5 7ZqT5bFLtiPHVjKOzeSUG/aInXnJVaxbHeyQjMsIQ3wcekLepzXyLPPGq190oLyY2G2T OhDJOpmVSuFAWxgpB/9sL6wJjHSr/pebeu2XU2tXzimcVTYNZwwehmdPue/hn4azlLbl 1xzw== X-Gm-Message-State: AFqh2kqEsZdYSVaorrKPQfYDrJ9Q2kUisZLHrIozZIrEopFUK2alLjGO LApA5atJg/0EolMq79nGsAUovrzNc7h0aTuw X-Received: by 2002:aca:d80b:0:b0:366:bfc6:4a78 with SMTP id p11-20020acad80b000000b00366bfc64a78mr19838189oig.20.1675061080625; Sun, 29 Jan 2023 22:44:40 -0800 (PST) Received: from wedsonaf-dev.home.lan ([189.124.190.154]) by smtp.googlemail.com with ESMTPSA id o64-20020aca5a43000000b003670342726fsm4427883oib.12.2023.01.29.22.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 22:44:40 -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 , Vincenzo Palazzo Subject: [PATCH v2 4/5] rust: types: implement `ForeignOwnable` for the unit type Date: Mon, 30 Jan 2023 03:44:03 -0300 Message-Id: <20230130064404.744600-4-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130064404.744600-1-wedsonaf@gmail.com> References: <20230130064404.744600-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?1756429025810371290?= X-GMAIL-MSGID: =?utf-8?q?1756429025810371290?= 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: Gary Guo 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.