Re: [PATCH v8 2/2] rust: add dma coherent allocator abstraction.

From: Abdiel Janulgue
Date: Thu Jan 09 2025 - 06:14:39 EST



On 08/01/2025 21:09, Daniel Almeida wrote:
I was trying to test this again, but it apparently doesn’t compile for the reasons
Daniel Sedlak pointed out above.


Okay, now I noticed the problem.

bindgen generates this rust signature for dma_alloc_attrs():

extern "C" {
pub fn dma_alloc_attrs(
dev: *mut device,
size: usize,
dma_handle: *mut dma_addr_t,
flag: gfp_t,
attrs: ffi::c_ulong,
) -> *mut ffi::c_void;
}

We are interested in the last argument 'attrs'. For some reason it seems ffi::c_ulong is defined as usize at least on top of `rust-next` commit 0c5928deada15a8d075516e6e0d9ee19011bb000.

In previous versions ffi::c_ulong used to be u64. I also noticed that core::ffi::c_ulong is u64 while crate::ffi::c_ulong is usize. In the previous versions they're both u64.

So my mistake here as is I tried to match the signature manually by using usize as suggested by the compiler. Maybe we should stick to ffi::c_ulong return type for Attrs::as_raw() to be in sync the bindgen-generated interface?

Regards,
Abdiel