From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 595A023BF9C for ; Mon, 14 Jul 2025 11:51:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752493877; cv=none; b=kClnChvxu5uM4186qwpTClqX0kQxnK+xYNIiSULokRrYmhK053M7oP+FHZZPAbtepMM6oEOyUo5/nIXwvsfDpMBhdZqM2yqrCjPkCqq5utqJkoyPvXY4SnaNuGNi68VX4+QsVXiobEwEBFi+qgfjMkHkEx8UIxfomVxcNju4TUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752493877; c=relaxed/simple; bh=1fOsxm8KmM+d67Cn3Rpd/LbmTkIxTdxW+gtVkoYk/EM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A86WoQsMPJ2pKwuPeF8SMX74DjrJtxhaziNZ8e+H9FMY/Ru9l7vvZsRQObrj2S/wK9uiV+GAKkftlJrP4Oig4igijDYFRAxApS5PO2e1LK3flaj/vMRXUHDVpe7eztt3gHE4iO4ebrqoRb5LaZC/4ou6LBVY2OOKVT2AR+fetlw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=c8TbDo2l; arc=none smtp.client-ip=209.85.128.74 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--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c8TbDo2l" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-450df53d461so32914925e9.1 for ; Mon, 14 Jul 2025 04:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752493874; x=1753098674; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=NO40oCgQSCqkHXjzs0s5Ot/ig0QEzwHdR9AJ2G+vIrQ=; b=c8TbDo2laNPCLHRuD64xsmF0pIAJLUJGwrbOO1jr+qvgB3+JHf4XCXq5VzS3G2yYcn FJChxJ0DypWrydJRVjhGuxCGDMJpJ4wrssa2OIUmRDypOEkIenLaVG4rlLPVsVxtQJ2P PcMgPLfL+++oWGAdN0pv2uv0dYFAJcUWIse5OaWsVMq9/IZFzS/Rib+CKXrIXglVWHZ2 xd7t+FXds/6tH6O2Da+J6OHtV7OcTAyk0Q1QjmZIVuSLJDk84L6fncSpzyf9NKz3/0wZ eoBWGSEVfEiR8CTf+PYUXhkaFezYg5Cm/UDpCbJoCBeSD99TV+B6rKRp1+mOBzCNO9xO ClDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752493874; x=1753098674; h=content-transfer-encoding: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=NO40oCgQSCqkHXjzs0s5Ot/ig0QEzwHdR9AJ2G+vIrQ=; b=HO9OSVs8O9m59YF00H9WSUpeKS6iubz/FpTwsAucpla3rbPk3HrfQmxzMxaIKWig2Q 26tS/XNMIPN3r3MsEtEomD7MsFPi7yjTvkTN5+B3bYVv0POBhyLACfX9FNIT5zeVqxC/ DK8ocMfGWDddkuMX89HxCjPuipK4RTJMluxy568meXzPv5Rh/NlbNaN7a5onbzR1xeit S0e/WFNAhuHS5blWc7TDiUX5Gs8xHNY4Alg61tCgMGBs55CKw6DUuh19JvKh2Jma3NGH jFjx2UHz5qltdhT6BhKcJJWmEc7XM6yDFQYc8bzqY0BWzR2S02CQy0qeDcLDjyWmKYAN JUyA== X-Forwarded-Encrypted: i=1; AJvYcCVkPTKNLCbhu1IGmTjAwJ3y+R7NraEYe9G8LWcatZEkvpD7OvCHJ0W3N1CAW4yQmLG+m3kWjciG5DXs3Terjg==@vger.kernel.org X-Gm-Message-State: AOJu0Yx8B7ofOqcIWlONWUsphT3Bxom2Clf2uQlHeQ3UQ8CqAGjKHwqy j/Y36fCevRQSBmTOtPvLs3fORVK9vBmjXZb9y0UYRHEYqlOrGbCRVNSxJC0XjnIICdcGBLNxRCH PgOQgvSTd3fBuBETy6Q== X-Google-Smtp-Source: AGHT+IEC1AXUVxbsXuFfTt+kmPJ2lYfWegg79vPCpBaWdc+ofzAvJ1LZKa5QpJGV+AetC0pRA+Pf3Rt8j/eWnog= X-Received: from wmbel18.prod.google.com ([2002:a05:600c:3e12:b0:456:1194:a7e7]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:314e:b0:456:1204:e7ec with SMTP id 5b1f17b1804b1-4561204e9d5mr60923015e9.10.1752493873725; Mon, 14 Jul 2025 04:51:13 -0700 (PDT) Date: Mon, 14 Jul 2025 11:51:12 +0000 In-Reply-To: <7A0457FA-0E09-451E-B035-E739AED7B2C7@collabora.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250704-topics-tyr-platform_iomem-v12-0-1d3d4bd8207d@collabora.com> <20250704-topics-tyr-platform_iomem-v12-2-1d3d4bd8207d@collabora.com> <7A0457FA-0E09-451E-B035-E739AED7B2C7@collabora.com> Message-ID: Subject: Re: [PATCH v12 2/3] rust: io: mem: add a generic iomem abstraction From: Alice Ryhl To: Daniel Almeida Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , Andy Shevchenko , "Ilpo =?utf-8?B?SsOkcnZpbmVu?=" , Bjorn Helgaas , Mika Westerberg , Ying Huang , Benno Lossin , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Jul 10, 2025 at 10:58:13AM -0300, Daniel Almeida wrote: > Hi Alice, >=20 > >> +impl IoMem { > >> + fn ioremap(resource: &Resource) -> Result { > >> + let size =3D resource.size(); > >> + if size =3D=3D 0 { > >> + return Err(EINVAL); > >> + } > >> + > >> + let res_start =3D resource.start(); > >> + > >> + let addr =3D if resource > >> + .flags() > >> + .contains(io::resource::flags::IORESOURCE_MEM_NONPOSTED) > >> + { > >> + // SAFETY: > >> + // - `res_start` and `size` are read from a presumably va= lid `struct resource`. > >> + // - `size` is known not to be zero at this point. > >> + unsafe { bindings::ioremap_np(res_start, size as usize) } > >=20 > > Here you cast from ResourceSize to usize. Are you sure that is correct? > > I thought those types could be different. >=20 > This seems to what C is doing as well, i.e.: >=20 > static void __iomem *__devm_ioremap(struct device *dev, resource_size_t o= ffset, > resource_size_t size, <--------- > enum devm_ioremap_type type) > { >=20 > [=E2=80=A6] >=20 > case DEVM_IOREMAP_NP: > addr =3D ioremap_np(offset, size); > break; > } >=20 >=20 > Where: >=20 > `static inline void __iomem *ioremap_np(phys_addr_t offset, size_t size)` >=20 > IOW: this stems from the mix and match of types used the C API itself. >=20 > What do you suggest here? Maybe a try_into() then? What a mess. It looks like there aren't any 32-bit architectures that define ioremap_np. This means that sometimes this cast will be lossy, but in those cases the function body just returns NULL and doesn't read the size. I would probably cast to an underscore instead of explicitly mentioning the target type and make a comment about it. Alice