Re: [PATCH V2 2/2] rust: Add basic bindings for clk APIs
From: Daniel Almeida
Date: Fri Feb 21 2025 - 09:42:58 EST
> +
> +use crate::{
> + bindings,
> + device::Device,
> + error::{from_err_ptr, to_result, Result},
> + prelude::*,
> +};
> +
> +use core::ptr;
> +
> +/// A simple implementation of `struct clk` from the C code.
> +#[repr(transparent)]
> +pub struct Clk(*mut bindings::clk);
> +
> +impl Clk {
> + /// Creates `Clk` instance for a device and a connection id.
> + pub fn new(dev: &Device, name: Option<&CStr>) -> Result<Self> {
> + let con_id = if let Some(name) = name {
> + name.as_ptr() as *const _
> + } else {
> + ptr::null()
> + };
Viresh, one thing I forgot to comment. Maybe it’s better if we keep the
`get` nomenclature here instead of `new`.
This is to make clear that nothing is getting spawned. A reference to a system
resource is (potentially) being returned instead.
This would also mean refactoring the docs for this function.
— Daniel