From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E5E73BFE45 for ; Tue, 3 Feb 2026 15:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770133604; cv=none; b=ZQVogo//MFk0D8l4bDQO3MqTGyllBi1S+nAFPCIhj6V9g+iIk/aUmwE5OrWEcgue/n3FbmgyOpCx/WKcMzxXzjc4WopNRXGrNv++rRMWesNfenEtimV8jFOjZZp1aPE/AAXDxn4qGM6p6jnsjOA6jrswZeh5os1M0hvkMwgXwEw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770133604; c=relaxed/simple; bh=RwCJ/xEwqbjligRdRo7donBAUlsdrVxdbuTW9DJLV3g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EoxK3tnwyoIe0s5hD/87rXsYOhHy3RsRkb+Gekl5rDAp+uE2lhCHEYx1uqbN0NMtsj+LjnBQ6OFrrNoG7Hnc2NPbTfLSKI0WvgMJizbgFWLsBzqgzDM8hY6L8zWbC9Mjot6bOyhTKCV4wuA94GxeU7QRtVq0Bzchvrd9vNxAiCo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QWWpbDi+; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mmaurer.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QWWpbDi+" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b74aff34efso10550371eec.1 for ; Tue, 03 Feb 2026 07:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1770133600; x=1770738400; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KdXVf1jtiVVdnaqb+rLnoB8/QmUjcxzniTwKjo2bXrU=; b=QWWpbDi+07DEGZt/vbKJ4gHNZQvQ9xKkTh6732LHW4Pw7iLWmQPaPw40lm/jK1iXFv RsaY+EyR9ugT8iRjNWYsQIz1WYyFkALVnbRps2rNI4MePXVn+R3HTfn0sd47SAYRESmm VdM68Uzak3YXOm3T1MiTs9pny8iOXHAQNiiR7Bh2L17xpL4bISRbqjE8xe8bNPD/bimA q/3aMkFxtIKqOqH49AuO4K/nB7Hwzc7iyMgpG40QINdvujP6h3q2gDd1SxJ0DR4OehQW YlWFgqYRM8NgxMibh9YHCkNx1FQ84lHH14/keobHJFY1ilaYorqUT27KXV8kqoFJVS7N W85A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770133600; x=1770738400; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KdXVf1jtiVVdnaqb+rLnoB8/QmUjcxzniTwKjo2bXrU=; b=D4YzPRVmUrDoqi9cRUC7vsPHOSpVA1RpzUiUq938AiHDgj5GpKhSR7k4FiGYe1qmNv JkCTC96f/16t8eem2vpq2+nbn49H3KsdAfPaqeWU6VGgkVsZ//Vepv6rcuhal+XZigPJ XR6EoezFCkQWPxiwzbUnpAY9Ininh7oGEhKl8nbzp7TAs7I11vjE2zIP+fat6N4HrUmy +VVwBKss9ooOlIG0/SUubLiid0SXDtAGEioM7SIXtcQdSpgU3M/hjFDq/vBU4nh47R1j g0ZJ7Fsz+PineCMwWhkNFOntyvB1av/U8yz92yGRIHIcZUmFfn4sMSwbg7f64/S1JZhI uZ8g== X-Forwarded-Encrypted: i=1; AJvYcCU5JyuBXrfFLxFPLyrNoWKp/2aY3oKMYYWRHndEXfjK2odIt3LdrKNjcLQ/i4HL1HBmOiNdAXloW7lS47wB@vger.kernel.org X-Gm-Message-State: AOJu0YwPO3nNAy2jgXf9V24YcSIMo5ng7g6OPe2sppo1XOkTDPHVkrMg 7sX0bNUSSJpZvz9KTRepdLASyV8wlZByXwS+XAlM9yW6ujnj/5HBvLI0ikRb0chU66/HjhAlrZJ zBVhi+GistQ== X-Received: from dycrt20.prod.google.com ([2002:a05:693c:2d94:b0:2b6:c6a7:636a]) (user=mmaurer job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3002:b0:2b6:c617:f795 with SMTP id 5a478bee46e88-2b7c86663c1mr7418033eec.17.1770133600442; Tue, 03 Feb 2026 07:46:40 -0800 (PST) Date: Tue, 03 Feb 2026 15:46:32 +0000 In-Reply-To: <20260203-qcom-socinfo-v2-0-d6719db85637@google.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260203-qcom-socinfo-v2-0-d6719db85637@google.com> X-Developer-Key: i=mmaurer@google.com; a=ed25519; pk=2Ezhl7+fEjTOMVFpplDeak2AdQ8cjJieLRVJdNzrW+E= X-Developer-Signature: v=1; a=ed25519-sha256; t=1770133593; l=2963; i=mmaurer@google.com; s=20250429; h=from:subject:message-id; bh=RwCJ/xEwqbjligRdRo7donBAUlsdrVxdbuTW9DJLV3g=; b=SQdCmaIOesp2nNqbcmI1qfM3G5NEMlAiTI7JoMUcwHSNW8vyq+fqK1lL17+OwnTzARN5rGU+z 9PyU4DL3NSyDmB3rGdnOpkIMgMGTW/9HGTk/h/gqJgPbPfyQrUyBmYk X-Mailer: b4 0.14.2 Message-ID: <20260203-qcom-socinfo-v2-3-d6719db85637@google.com> Subject: [PATCH v2 3/6] rust: device: Support testing devices for equality From: Matthew Maurer To: Bjorn Andersson , Konrad Dybcio , Satya Durga Srinivasu Prabhala , Miguel Ojeda , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Michal Wilczynski , Dave Ertman , Ira Weiny , Leon Romanovsky Cc: Trilok Soni , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, rust-for-linux@vger.kernel.org, driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-pwm@vger.kernel.org, Matthew Maurer Content-Type: text/plain; charset="utf-8" This allows device drivers to check if, for example, an auxiliary devices is one of its children by comparing the parent field, or checking if a device parameter is its own device. Also convert existing `.as_raw() != .as_raw()` to use this new implementation. Signed-off-by: Matthew Maurer --- rust/kernel/device.rs | 8 ++++++++ rust/kernel/devres.rs | 2 +- rust/kernel/drm/driver.rs | 2 +- rust/kernel/pwm.rs | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs index 94e0548e76871d8b7de309c1f1c7b77bb49738ed..aa10359d3ebdd1c99cc567a35b89f52ddb2ee050 100644 --- a/rust/kernel/device.rs +++ b/rust/kernel/device.rs @@ -516,6 +516,14 @@ unsafe impl Send for Device {} // synchronization in `struct device`. unsafe impl Sync for Device {} +impl PartialEq> for Device { + fn eq(&self, other: &Device) -> bool { + self.as_raw() == other.as_raw() + } +} + +impl Eq for Device {} + /// Marker trait for the context or scope of a bus specific device. /// /// [`DeviceContext`] is a marker trait for types representing the context of a bus specific diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index cdc49677022a6b466e771d9d8cf3818ab9b9112d..20126daad193370868661b9412937937eda6d3c4 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -281,7 +281,7 @@ pub fn device(&self) -> &Device { /// } /// ``` pub fn access<'a>(&'a self, dev: &'a Device) -> Result<&'a T> { - if self.dev.as_raw() != dev.as_raw() { + if self.dev.as_ref() != dev { return Err(EINVAL); } diff --git a/rust/kernel/drm/driver.rs b/rust/kernel/drm/driver.rs index f30ee4c6245cda72ac72852bf9362736d8fe992f..497ef46028d560bc9649dbbdf69316ce4fce8199 100644 --- a/rust/kernel/drm/driver.rs +++ b/rust/kernel/drm/driver.rs @@ -139,7 +139,7 @@ pub fn new_foreign_owned( where T: 'static, { - if drm.as_ref().as_raw() != dev.as_raw() { + if drm.as_ref() != dev { return Err(EINVAL); } diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs index cb00f8a8765c8ec58ed78a73275b022b02bf7aa3..033f778909a2633acbc25d5a21a1c8a7b8e41a70 100644 --- a/rust/kernel/pwm.rs +++ b/rust/kernel/pwm.rs @@ -680,7 +680,7 @@ impl Registration { /// calling `pwmchip_remove`. This function should be called from the driver's `probe`. pub fn register(dev: &device::Device, chip: ARef>) -> Result { let chip_parent = chip.device().parent().ok_or(EINVAL)?; - if dev.as_raw() != chip_parent.as_raw() { + if dev != chip_parent { return Err(EINVAL); } -- 2.53.0.rc2.204.g2597b5adb4-goog