rust: pci: use 'static lifetime for PCI BAR resource names

pci_request_region() stores the name pointer directly in struct
resource; use &'static CStr to ensure the pointer remains valid even if
the Bar is leaked.

Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260522004943.CDA7C1F000E9@smtp.kernel.org/
Fixes: 3c2e31d717 ("rust: pci: move I/O infrastructure to separate file")
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260525202921.124698-2-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Danilo Krummrich 2026-05-25 22:20:48 +02:00
parent 95ade775c4
commit e566a9e17f

View File

@ -153,7 +153,7 @@ pub struct Bar<const SIZE: usize = 0> {
}
impl<const SIZE: usize> Bar<SIZE> {
pub(super) fn new(pdev: &Device, num: u32, name: &CStr) -> Result<Self> {
pub(super) fn new(pdev: &Device, num: u32, name: &'static CStr) -> Result<Self> {
let len = pdev.resource_len(num)?;
if len == 0 {
return Err(ENOMEM);
@ -252,7 +252,7 @@ impl Device<device::Bound> {
pub fn iomap_region_sized<'a, const SIZE: usize>(
&'a self,
bar: u32,
name: &'a CStr,
name: &'static CStr,
) -> impl PinInit<Devres<Bar<SIZE>>, Error> + 'a {
Devres::new(self.as_ref(), Bar::<SIZE>::new(self, bar, name))
}
@ -261,7 +261,7 @@ pub fn iomap_region_sized<'a, const SIZE: usize>(
pub fn iomap_region<'a>(
&'a self,
bar: u32,
name: &'a CStr,
name: &'static CStr,
) -> impl PinInit<Devres<Bar>, Error> + 'a {
self.iomap_region_sized::<0>(bar, name)
}