Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2058F1F0E26 for ; Tue, 13 May 2025 22:11:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747174268; cv=none; b=BRrRO2/qAE/wMJFNujrnQGz1V5bxB31fkGQE0HgYvEDxIPsK5bMISli5IJVJE0LAL5iCBFxkgBS7xiQHt4URxcimRS2DY0KrX9DY4ccgQ1oblTefQXQwI0OcLlZRnK9ZrZRn2dtYWGjY7nwPSw5l1EXj9S/Etg/kptiSa3G24fE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747174268; c=relaxed/simple; bh=KoVg+RCs4hMlFuoabocT3S/EpmV31xnUshELhfpKYDk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J/iQB9bzjFQecGFgmnbPWpyy8+xyaHIxgkQTfTPsWiczO804P300tDrZG2ZKNPUKgXX/+Yj6+jPDzMS4e7TG1wEmitRGJiBKoPws9fgJbINftWbxQaBy5yGU7FyyavudlLe3Jca0whX1P7iPAqt8fZoi87HJGyejIcnSLPbfMSM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SnAThFk+; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SnAThFk+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747174266; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DCw2wvd2m1wTO/RjJyxO6cpVaBvDfLJZ2984Y/kSd2U=; b=SnAThFk+yMENEKlArQ9SR2wNoBmiKszhQ0cfvzKrPFjrr908oMsR7rgy/e6BVA1y70PKuL u4ej+J/s2Wz4Ja9GJsbZSm9seo4GDH/LX5NGDvI8E+3anm5f75quVVHNuuFFsYapmNTw3X JosD4Aa0JSzI0t0LeYP4f6A7YmG9ezA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-wm0OVJk3O6makUvGSG_Vyg-1; Tue, 13 May 2025 18:11:03 -0400 X-MC-Unique: wm0OVJk3O6makUvGSG_Vyg-1 X-Mimecast-MFC-AGG-ID: wm0OVJk3O6makUvGSG_Vyg_1747174261 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6859A195DE0B; Tue, 13 May 2025 22:11:00 +0000 (UTC) Received: from chopper.lyude.net (unknown [10.22.64.99]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 577821940E95; Tue, 13 May 2025 22:10:55 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Cc: Daniel Almeida , Danilo Krummrich , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Asahi Lina , Alyssa Rosenzweig Subject: [PATCH v2 1/4] rust: drm: gem: Use NonNull for Object::dev Date: Tue, 13 May 2025 18:09:54 -0400 Message-ID: <20250513221046.903358-2-lyude@redhat.com> In-Reply-To: <20250513221046.903358-1-lyude@redhat.com> References: <20250513221046.903358-1-lyude@redhat.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 There is usually not much of a reason to use a raw pointer in a data struct, so move this to NonNull instead. Signed-off-by: Lyude Paul Reviewed-by: Daniel Almeida Reviewed-by: Danilo Krummrich --- rust/kernel/drm/gem/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs index 0cafa4a424206..df8f9fdae5c22 100644 --- a/rust/kernel/drm/gem/mod.rs +++ b/rust/kernel/drm/gem/mod.rs @@ -177,7 +177,7 @@ impl BaseObject for T where Self: crate::types::AlwaysRefCounted + IntoGEMObj #[pin_data] pub struct Object { obj: Opaque, - dev: *const drm::Device, + dev: NonNull>, #[pin] data: T, } @@ -212,7 +212,7 @@ pub fn new(dev: &drm::Device, size: usize) -> Result> { data <- T::new(dev, size), // INVARIANT: The drm subsystem guarantees that the `struct drm_device` will live // as long as the GEM object lives. - dev, + dev: dev.into(), }), GFP_KERNEL, )?; @@ -237,7 +237,7 @@ pub fn new(dev: &drm::Device, size: usize) -> Result> { pub fn dev(&self) -> &drm::Device { // SAFETY: The DRM subsystem guarantees that the `struct drm_device` will live as long as // the GEM object lives, hence the pointer must be valid. - unsafe { &*self.dev } + unsafe { self.dev.as_ref() } } fn as_raw(&self) -> *mut bindings::drm_gem_object { -- 2.49.0