Skip to content

Commit c1b4071

Browse files
fujitaojeda
authored andcommitted
rust: helpers: Add dma_alloc_attrs() and dma_free_attrs()
Add dma_alloc_attrs() and dma_free_attrs() helpers to fix a build error when CONFIG_HAS_DMA is not enabled. Note that when CONFIG_HAS_DMA is enabled, dma_alloc_attrs() and dma_free_attrs() are included in both bindings_generated.rs and bindings_helpers_generated.rs. The former takes precedence so behavior remains unchanged in that case. 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` | ::: 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` | ::: 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: ad2907b ("rust: add dma coherent allocator abstraction") Signed-off-by: FUJITA Tomonori <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Reworded for relative paths. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 584e614 commit c1b4071

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

MAINTAINERS

+1
Original file line numberDiff line numberDiff line change
@@ -7020,6 +7020,7 @@ L: [email protected]
70207020
S: Supported
70217021
W: https://rust-for-linux.com
70227022
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
7023+
F: rust/helpers/dma.c
70237024
F: rust/kernel/dma.rs
70247025
F: samples/rust/rust_dma.rs
70257026

rust/helpers/dma.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/dma-mapping.h>
4+
5+
void *rust_helper_dma_alloc_attrs(struct device *dev, size_t size,
6+
dma_addr_t *dma_handle, gfp_t flag,
7+
unsigned long attrs)
8+
{
9+
return dma_alloc_attrs(dev, size, dma_handle, flag, attrs);
10+
}
11+
12+
void rust_helper_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
13+
dma_addr_t dma_handle, unsigned long attrs)
14+
{
15+
dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs);
16+
}

rust/helpers/helpers.c

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "cpumask.c"
1515
#include "cred.c"
1616
#include "device.c"
17+
#include "dma.c"
1718
#include "err.c"
1819
#include "fs.c"
1920
#include "io.c"

0 commit comments

Comments
 (0)