Re: [PATCH V2 2/2] rust: Add basic bindings for clk APIs
From: Rob Herring
Date: Wed Mar 05 2025 - 15:10:16 EST
On Mon, Feb 24, 2025 at 4:00 AM Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
>
> On 21-02-25, 15:59, Rob Herring wrote:
> > It would be nice to handle the optional case from the start. Otherwise,
> > driver writers handle optional or not optional themselves. The not
> > optional case is typically some form of error message duplicated in
> > every driver.
> >
> > Every foo_get() needs foo_get_optional(), so let's figure out the rust
> > way to handle this once for everyone.
>
> Are we talking about adding another field here (like below code) or
> something else ?
Either way, but generally I think 2 functions are preferred over 1
function and flags.
The harder part here is in C we just return NULL and all subsequent
functions (e.g. clk_enable()) just return with no error for a NULL
struct clk. For rust, I think we'd need a dummy Clk returned and then
handle comparing the passed in reference to the dummy Clk in the rust
bindings.
>
> impl Clk {
> pub fn get(dev: &Device, name: Option<&CStr>, optional: bool) -> Result<Self> {
> ...
>
> let clk = if optional {
> bindings::clk_get(dev.as_raw(), con_id)
> else {
> bindings::clk_get_optional(dev.as_raw(), con_id)
> };
>
> Ok(Self(from_err_ptr(clk)?))
> }
> }
>
> --
> viresh