Bindgen generates constants for CPP integer literals as u32. The `blk_status_t` type is defined as `u8` but the variants of the type are defined as integer literals via CPP macros. Thus the defined variants of the type are not of the same type as the type itself. Prevent bindgen from emitting generated bindings for the `BLK_STS_.*` defines and instead define constants manually in `bindings_helper.h` Also remove casts that are no longer necessary. Reviewed-by: Alice Ryhl Signed-off-by: Andreas Hindborg --- rust/bindgen_parameters | 6 ++++++ rust/bindings/bindings_helper.h | 19 +++++++++++++++++++ rust/kernel/block/mq/operations.rs | 17 +++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/rust/bindgen_parameters b/rust/bindgen_parameters index 6f02d9720ad2..128731e84775 100644 --- a/rust/bindgen_parameters +++ b/rust/bindgen_parameters @@ -5,6 +5,12 @@ --blocklist-type __kernel_s?size_t --blocklist-type __kernel_ptrdiff_t +# Bindgen cannot extract values from the `((__force blk_status_t)N)` +# CPP-macro form used by most of these and emits the few it can extract +# as `u32`. Block them entirely; the `RUST_CONST_HELPER_BLK_STS_*` +# definitions in `bindings_helper.h` expose them as `blk_status_t`. +--blocklist-item BLK_STS_.* + --opaque-type xregs_state --opaque-type desc_struct --opaque-type arch_lbr_state diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 9da216faad51..b1fb3afee4ca 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -119,6 +119,25 @@ const gfp_t RUST_CONST_HELPER___GFP_ZERO = __GFP_ZERO; const gfp_t RUST_CONST_HELPER___GFP_HIGHMEM = ___GFP_HIGHMEM; const gfp_t RUST_CONST_HELPER___GFP_NOWARN = ___GFP_NOWARN; const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ROTATIONAL = BLK_FEAT_ROTATIONAL; +const blk_status_t RUST_CONST_HELPER_BLK_STS_OK = BLK_STS_OK; +const blk_status_t RUST_CONST_HELPER_BLK_STS_NOTSUPP = BLK_STS_NOTSUPP; +const blk_status_t RUST_CONST_HELPER_BLK_STS_TIMEOUT = BLK_STS_TIMEOUT; +const blk_status_t RUST_CONST_HELPER_BLK_STS_NOSPC = BLK_STS_NOSPC; +const blk_status_t RUST_CONST_HELPER_BLK_STS_TRANSPORT = BLK_STS_TRANSPORT; +const blk_status_t RUST_CONST_HELPER_BLK_STS_TARGET = BLK_STS_TARGET; +const blk_status_t RUST_CONST_HELPER_BLK_STS_RESV_CONFLICT = BLK_STS_RESV_CONFLICT; +const blk_status_t RUST_CONST_HELPER_BLK_STS_MEDIUM = BLK_STS_MEDIUM; +const blk_status_t RUST_CONST_HELPER_BLK_STS_PROTECTION = BLK_STS_PROTECTION; +const blk_status_t RUST_CONST_HELPER_BLK_STS_RESOURCE = BLK_STS_RESOURCE; +const blk_status_t RUST_CONST_HELPER_BLK_STS_IOERR = BLK_STS_IOERR; +const blk_status_t RUST_CONST_HELPER_BLK_STS_DM_REQUEUE = BLK_STS_DM_REQUEUE; +const blk_status_t RUST_CONST_HELPER_BLK_STS_AGAIN = BLK_STS_AGAIN; +const blk_status_t RUST_CONST_HELPER_BLK_STS_DEV_RESOURCE = BLK_STS_DEV_RESOURCE; +const blk_status_t RUST_CONST_HELPER_BLK_STS_ZONE_OPEN_RESOURCE = BLK_STS_ZONE_OPEN_RESOURCE; +const blk_status_t RUST_CONST_HELPER_BLK_STS_ZONE_ACTIVE_RESOURCE = BLK_STS_ZONE_ACTIVE_RESOURCE; +const blk_status_t RUST_CONST_HELPER_BLK_STS_OFFLINE = BLK_STS_OFFLINE; +const blk_status_t RUST_CONST_HELPER_BLK_STS_DURATION_LIMIT = BLK_STS_DURATION_LIMIT; +const blk_status_t RUST_CONST_HELPER_BLK_STS_INVAL = BLK_STS_INVAL; const fop_flags_t RUST_CONST_HELPER_FOP_UNSIGNED_OFFSET = FOP_UNSIGNED_OFFSET; const xa_mark_t RUST_CONST_HELPER_XA_PRESENT = XA_PRESENT; diff --git a/rust/kernel/block/mq/operations.rs b/rust/kernel/block/mq/operations.rs index 89029f468f44..6b2fcd76372e 100644 --- a/rust/kernel/block/mq/operations.rs +++ b/rust/kernel/block/mq/operations.rs @@ -6,10 +6,19 @@ use crate::{ bindings, - block::mq::{request::RequestDataWrapper, Request}, - error::{from_result, Result}, + block::mq::{ + request::RequestDataWrapper, + Request, // + }, + error::{ + from_result, + Result, // + }, prelude::*, - sync::{aref::ARef, Refcount}, + sync::{ + aref::ARef, + Refcount, // + }, types::ForeignOwnable, }; use core::marker::PhantomData; @@ -124,7 +133,7 @@ impl OperationsVTable { if let Err(e) = ret { e.to_blk_status() } else { - bindings::BLK_STS_OK as bindings::blk_status_t + bindings::BLK_STS_OK } } -- 2.51.2