Skip to content

Conversation

@maurer
Copy link

@maurer maurer commented Dec 5, 2025

The inspiration for this change is mostly modeled by the split test below. The real world case looks like this:

impl platform::Driver for QcomSocInfo {                                                                                                                                               
    type IdInfo = ();                                                                                                                                                                 
    const OF_ID_TABLE: Option<kernel::of::IdTable<Self::IdInfo>> = None;                                                                                                              
    fn probe(_dev: &Device<Core>, _id_info: Option<&Self::IdInfo>) -> impl PinInit<Self, Error> {                                                                                     
        try_pin_init!(                                                                                                                                                                
            Self {                                                                                                                                                                    
                _: {                                                                                                                                                                  
                    let soc_info_mem = qcom_smem_get(                                                                                                                                 
                        kernel::bindings::QCOM_SMEM_HOST_ANY,                                                                                                                         
                        kernel::bindings::SMEM_HW_SW_BUILD_ID,                                                                                                                        
                    )?;                                                                                                                                                               
                    let version_mem = qcom_smem_get(                                                                                                                                  
                        kernel::bindings::QCOM_SMEM_HOST_ANY,                                                                                                                         
                        bindings::SMEM_IMAGE_VERSION_TABLE,                                                                                                                           
                    )?;                                                                                                                                                               
                    let info = SocInfo::from_mem(soc_info_mem, version_mem);                                                                                                          
                    let backing = info.build_params()?;                                                                                                                               
                    kernel::rand::add_device_randomness(soc_info_mem);                                                                                                                
                },                                                                                                                                                                    
                registration <- soc::DeviceRegistration::register(info.device_attribute()?),                                                                                          
                params <- Scope::dir(backing, c_str!("qcom_socinfo_rs_scoped"),                                                                                                       
                                     Params::build_debugfs),                                                                                                                          
            }                                                                                                                                                                         
        )                                                                                                                                                                             
    }                                                                                                                                                                                 
}  

Previously, I handled this by just putting the _: {} block before try_pin_init, and returning a Result<KBox<Self>, Error>, but the probe interface has changed.

@maurer maurer force-pushed the expose-bindings branch 3 times, most recently from 8c8ac52 to 7ecda0c Compare December 5, 2025 22:34
@BennoLossin
Copy link
Member

Have you seen #86? It's already merged by Danilo in the kernel and I'll merge it here soon as well.

@BennoLossin
Copy link
Member

BennoLossin commented Dec 5, 2025

I'd like to avoid making let bindings in _: {} escape it, since that will most likely not be the behavior that Rust will have when we get init expressions there.

Additionally to #86, I wanted to eventually do #69 which allows extending the body to a closure, so executing arbitrary code before the initializer in the macro

@maurer
Copy link
Author

maurer commented Dec 5, 2025

Have you seen #86? It's already merged by Danilo in the kernel and I'll merge it here soon as well.

Oh, if it's already merged I'll use that. I saw the PR was months old and thought it wasn't landing.

@maurer maurer closed this Dec 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants