rust/kernel/lib.rs | 1 + 1 file changed, 1 insertion(+)
Make dma abstraction conditional on CONFIG_HAS_DMA.
This fixes the following build error on UML:
error[E0425]: cannot find function `dma_alloc_attrs` in crate `bindings`
--> rust/kernel/dma.rs:171:23
|
171 | bindings::dma_alloc_attrs(
| ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_alloc_pages`
|
::: /home/fujita/build/um/rust/bindings/bindings_generated.rs:44568:5
|
44568 | / pub fn dma_alloc_pages(
44569 | | dev: *mut device,
44570 | | size: usize,
44571 | | dma_handle: *mut dma_addr_t,
44572 | | dir: dma_data_direction,
44573 | | gfp: gfp_t,
44574 | | ) -> *mut page;
| |___________________- similarly named function `dma_alloc_pages` defined here
error[E0425]: cannot find function `dma_free_attrs` in crate `bindings`
--> rust/kernel/dma.rs:293:23
|
293 | bindings::dma_free_attrs(
| ^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_free_pages`
|
::: /home/fujita/build/um/rust/bindings/bindings_generated.rs:44577:5
|
44577 | / pub fn dma_free_pages(
44578 | | dev: *mut device,
44579 | | size: usize,
44580 | | page: *mut page,
44581 | | dma_handle: dma_addr_t,
44582 | | dir: dma_data_direction,
44583 | | );
| |______- similarly named function `dma_free_pages` defined here
Fixes: ad2907b4e308 ("rust: add dma coherent allocator abstraction")
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/kernel/lib.rs | 1 +
1 file changed, 1 insertion(+)
diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
index de07aadd1ff5..9d743af69dc8 100644
--- a/rust/kernel/lib.rs
+++ b/rust/kernel/lib.rs
@@ -46,6 +46,7 @@
pub mod device;
pub mod device_id;
pub mod devres;
+#[cfg(CONFIG_HAS_DMA)]
pub mod dma;
pub mod driver;
pub mod error;
base-commit: c59026c0570a2a97ce2e7d5ae5e9c48fc841542b
--
2.43.0
On Wed, Apr 09, 2025 at 02:55:01PM +0900, FUJITA Tomonori wrote:
> Make dma abstraction conditional on CONFIG_HAS_DMA.
I'm not convinced that this is the correct fix. This would require drivers to
depend on CONFIG_HAS_DMA if they want to use the DMA API. The C side does not do
this either.
Instead, for functions like dma_alloc_attrs(), there is an empty implementation
if CONFIG_HAS_DMA is not set [1].
However, this definition is not picked up by bindgen. Hence, I think the actual
fix would be to introduce the corresponding Rust helpers.
[1] https://elixir.bootlin.com/linux/v6.13.7/source/include/linux/dma-mapping.h#L189
> This fixes the following build error on UML:
>
> error[E0425]: cannot find function `dma_alloc_attrs` in crate `bindings`
> --> rust/kernel/dma.rs:171:23
> |
> 171 | bindings::dma_alloc_attrs(
> | ^^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_alloc_pages`
> |
> ::: /home/fujita/build/um/rust/bindings/bindings_generated.rs:44568:5
> |
> 44568 | / pub fn dma_alloc_pages(
> 44569 | | dev: *mut device,
> 44570 | | size: usize,
> 44571 | | dma_handle: *mut dma_addr_t,
> 44572 | | dir: dma_data_direction,
> 44573 | | gfp: gfp_t,
> 44574 | | ) -> *mut page;
> | |___________________- similarly named function `dma_alloc_pages` defined here
>
> error[E0425]: cannot find function `dma_free_attrs` in crate `bindings`
> --> rust/kernel/dma.rs:293:23
> |
> 293 | bindings::dma_free_attrs(
> | ^^^^^^^^^^^^^^ help: a function with a similar name exists: `dma_free_pages`
> |
> ::: /home/fujita/build/um/rust/bindings/bindings_generated.rs:44577:5
> |
> 44577 | / pub fn dma_free_pages(
> 44578 | | dev: *mut device,
> 44579 | | size: usize,
> 44580 | | page: *mut page,
> 44581 | | dma_handle: dma_addr_t,
> 44582 | | dir: dma_data_direction,
> 44583 | | );
> | |______- similarly named function `dma_free_pages` defined here
>
> Fixes: ad2907b4e308 ("rust: add dma coherent allocator abstraction")
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> ---
> rust/kernel/lib.rs | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index de07aadd1ff5..9d743af69dc8 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -46,6 +46,7 @@
> pub mod device;
> pub mod device_id;
> pub mod devres;
> +#[cfg(CONFIG_HAS_DMA)]
> pub mod dma;
> pub mod driver;
> pub mod error;
>
> base-commit: c59026c0570a2a97ce2e7d5ae5e9c48fc841542b
> --
> 2.43.0
>
On Wed, 9 Apr 2025 11:07:02 +0200 Danilo Krummrich <dakr@kernel.org> wrote: > On Wed, Apr 09, 2025 at 02:55:01PM +0900, FUJITA Tomonori wrote: >> Make dma abstraction conditional on CONFIG_HAS_DMA. > > I'm not convinced that this is the correct fix. This would require drivers to > depend on CONFIG_HAS_DMA if they want to use the DMA API. The C side does not do > this either. > > Instead, for functions like dma_alloc_attrs(), there is an empty implementation > if CONFIG_HAS_DMA is not set [1]. Good point. > However, this definition is not picked up by bindgen. Hence, I think the actual > fix would be to introduce the corresponding Rust helpers. > > [1] https://elixir.bootlin.com/linux/v6.13.7/source/include/linux/dma-mapping.h#L189 I'll go with that approach for the next version. Thanks,
© 2016 - 2026 Red Hat, Inc.