From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 02BB72046B3; Sat, 19 Jul 2025 13:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752930945; cv=none; b=dUp5Ly8x8plGiOFiCt7adF60JNp8l75XnuOzQhDqRIEqJJ/in/liNZBPQiOgMMvxa5+oVNyBkykyLP2dccZQF1Iy0aycf65Hb1IZldsJ1PhMv2HKze/STd7xCEzY3/zs/cRGsvkOGoF4BVVO8Z+Neozs4yw/HFtlzwl67q+LqsI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752930945; c=relaxed/simple; bh=Q9CjqBh6qRR1VX7PfQpXfa7t2Y7m39HLcLpR1Xe++J4=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:To:From:Subject: References:In-Reply-To; b=aWoH4g92AovmiGgxeaNwq7T84wCF4BqYQwnjOGVmdfVmTM+y2vX4c9ur9jy8+/FZZYliKTSZirZO3hJd+UViDSDwNbUb+wAfBdxSYRqoZMlm1FL0Tkk3KjXuxkdl7eJUsodGCSev6QATuxZdBtjuSc5kUuHdeZQCBEobet71XSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LENUoug5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LENUoug5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E438DC4CEE3; Sat, 19 Jul 2025 13:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752930944; bh=Q9CjqBh6qRR1VX7PfQpXfa7t2Y7m39HLcLpR1Xe++J4=; h=Date:Cc:To:From:Subject:References:In-Reply-To:From; b=LENUoug5d0i4CU//Hmi6t/5JbY3FehDxlKxvS4BSHAAs2fd4XxTeI7FPsEybJhLCf HvPScU1xEvU09H3l2p6cmzlMqzgbMv31zvZJb/6vFa8d7QUd0Phjs/iZV7XqeAe1s5 y2Hs9W58I8aa4HfEsTY7pHK4/Tq4+pkLvBuTT1reYWZRdLmoN44nd8G12O2baFJnxo nrFa8mwceSE8fJHRloAtoABIlRiGbT8oBpxcwcfFBwKzLKzIDCLZQ94qxdcfJmY4Ny /vLnfCEeGFihr1H2iM8VmkhwRPAwG0Tigpd1eue+jLcrlciWJS9Hz2HmPNrFIuuAcM zXLQ/LvxKjFTw== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 19 Jul 2025 15:15:40 +0200 Message-Id: Cc: "Miguel Ojeda" , "Alex Gaynor" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Greg Kroah-Hartman" , "Rafael J. Wysocki" , , To: "Daniel Almeida" From: "Danilo Krummrich" Subject: Re: [PATCH v15 3/3] rust: platform: add resource accessors References: <20250717-topics-tyr-platform_iomem-v15-0-beca780b77e3@collabora.com> <20250717-topics-tyr-platform_iomem-v15-3-beca780b77e3@collabora.com> In-Reply-To: <20250717-topics-tyr-platform_iomem-v15-3-beca780b77e3@collabora.com> On Thu Jul 17, 2025 at 5:55 PM CEST, Daniel Almeida wrote: > +impl Device { > + /// Returns an `IoRequest` for the resource at `index`, if any. > + pub fn io_request_by_index(&self, index: u32) -> Option> { > + // SAFETY: `resource` is a valid resource for `&self` during the > + // lifetime of the `IoRequest`. > + self.resource_by_index(index) > + .map(|resource| unsafe { IoRequest::new(self.as_ref(), resou= rce) }) It seems there's a bug in some clippy versions we support. My regular testi= ng shows a warning for this with clippy 1.78: warning: unsafe block missing a safety comment --> rust/kernel/platform.rs:275:29 | 275 | .map(|resource| unsafe { IoRequest::new(self.as_ref(), r= esource) }) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^= ^^^^^^^^^^ | However, there clearly is a safety comment. It seems it gets confused by the multiline formatting. If I write this as self.resource_by_index(index) // SAFETY: `resource` is a valid resource for `&self` during the // lifetime of the `IoRequest`. .map(|resource| unsafe { IoRequest::new(self.as_ref(), resource) }) the warning goes away. @Miguel: What's the preferred way dealing with this? I assume we just want = to ignore this warning for the affected compiler versions? > + } > + > + /// Returns an `IoRequest` for the resource with a given `name`, if = any. > + pub fn io_request_by_name(&self, name: &CStr) -> Option> { > + // SAFETY: `resource` is a valid resource for `&self` during the > + // lifetime of the `IoRequest`. > + self.resource_by_name(name) > + .map(|resource| unsafe { IoRequest::new(self.as_ref(), resou= rce) }) > + } > }