From patchwork Mon May 20 17:20:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Danilo Krummrich X-Patchwork-Id: 13668500 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EBF3C25B79 for ; Mon, 20 May 2024 17:21:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7963E10E690; Mon, 20 May 2024 17:21:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="K6mB9qZO"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id C48EC10E690 for ; Mon, 20 May 2024 17:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716225696; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ieml4cQgLdOB6f1Tq+rgmDncA9spVWDVEosV1A4OpmA=; b=K6mB9qZOMfBH/2IW4JXa8B3L5GXokZVOvkQfJE3xCIAE6yvKTgOpjNoyCeu9IRasl09r3M zCVK2ldGpFZuRwO8VScJ5rB8ybI/w+lX1vFsQCWcP+8LW3f4yfGnWi5cnaFodp0khCqMSv 9HqWwbYYC+1O1eEOvjgXsnCH1gEIeM8= Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-ytS4i4duNt6qUACPbYwh_g-1; Mon, 20 May 2024 13:21:31 -0400 X-MC-Unique: ytS4i4duNt6qUACPbYwh_g-1 Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2e41bd70238so107412331fa.1 for ; Mon, 20 May 2024 10:21:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716225690; x=1716830490; 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=Ieml4cQgLdOB6f1Tq+rgmDncA9spVWDVEosV1A4OpmA=; b=v7NIwfm0Wi8cioH3ljU4sQ/xwsGHvgC/IcijeISGGOT1ISt3cmxs+8Dg5owrI1UFjY 2LmMj0jFgmruR0V39gXFqkEMDvIdR4O7gV6/G0OoAr8cvbnmbF2KMRX+COPKPjQgvrrP TSuxgynLI1vNp+YvP/MjneT6jfJJu2jvsjhgbJhivSqCYv2477X3wURDw8vtXAM6xfMv crpgdAj+1bcOJSmYYuHdWWNHDnzB5+S6g06gQGGNXLGelBqNN+UpHq8uUCh80Rd9hn1D bbOjSz94beexqjsNLGZrJNCNQ92r7Kl3XDFjnrXZNZJfc/s2XYNlxEwnKuUbK++DxUCJ yShA== X-Forwarded-Encrypted: i=1; AJvYcCXQphjmpYvVEe8YQ25WU3qzA2rDg1uKdPjrUPYjfysE23wOpNxca4BHpnzmaSYvzmjM2+ctwVkEHyeAXzSOQvLxW2gPPPql/DfgV0aTvwWI X-Gm-Message-State: AOJu0YwPHzcC2Xjs1tNemqd6Jmm8RVJbXOkLJ45qlk7UQlD9lY9SbfUM 5gqId3YTaJrJ1n9vx384KtoOaUFy+78vNJzOeQsRBllefCRhlEZ+FebTPywcBbd/L5YL3STjVsF 9/Yh+sLBe9nQzcBJ/pO7O7jHolQfYvbGiFvs8BPI93K99AeNl6KtE9tCzCXgVGHf5ng== X-Received: by 2002:a2e:d09:0:b0:2e5:2eaf:b095 with SMTP id 38308e7fff4ca-2e52eafb1f7mr191077721fa.39.1716225690430; Mon, 20 May 2024 10:21:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7q/RlyHXDaQZTvhlrA4Lq5+xbLf2b2bh7WpMR1SX2pe4dg+hi0hk9TL8lOhimdQzmJb/j0w== X-Received: by 2002:a2e:d09:0:b0:2e5:2eaf:b095 with SMTP id 38308e7fff4ca-2e52eafb1f7mr191077521fa.39.1716225690105; Mon, 20 May 2024 10:21:30 -0700 (PDT) Received: from cassiopeiae.. ([2a02:810d:4b3f:ee94:642:1aff:fe31:a19f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42013bf1a5dsm326293055e9.30.2024.05.20.10.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 10:21:27 -0700 (PDT) From: Danilo Krummrich To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, benno.lossin@proton.me, a.hindborg@samsung.com, aliceryhl@google.com, fujita.tomonori@gmail.com, lina@asahilina.net, pstanner@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, gregkh@linuxfoundation.org Cc: rust-for-linux@vger.kernel.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, Danilo Krummrich Subject: [RFC PATCH 4/8] rust: drm: implement `AsRef` for DRM device Date: Mon, 20 May 2024 19:20:51 +0200 Message-ID: <20240520172059.181256-5-dakr@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240520172059.181256-1-dakr@redhat.com> References: <20240520172059.181256-1-dakr@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Implement `AsRef` for `drm::device::Device` such that `dev_*` print macros can be used conveniently. Signed-off-by: Danilo Krummrich --- rust/kernel/drm/device.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/kernel/drm/device.rs b/rust/kernel/drm/device.rs index f72bab8dd42d..aef947893dab 100644 --- a/rust/kernel/drm/device.rs +++ b/rust/kernel/drm/device.rs @@ -79,6 +79,14 @@ unsafe fn dec_ref(obj: NonNull) { } } +impl AsRef for Device { + fn as_ref(&self) -> &device::Device { + // SAFETY: `bindings::drm_device::dev` is valid as long as the DRM device itself is valid, + // which is guaranteed by the type invariant. + unsafe { device::Device::as_ref((*self.as_raw()).dev) } + } +} + // SAFETY: `Device` only holds a pointer to a C device, which is safe to be used from any thread. unsafe impl Send for Device {}