Re: [PATCH V6 04/15] rust: device: Add few helpers

From: Greg Kroah-Hartman
Date: Wed Jan 08 2025 - 07:17:04 EST


On Wed, Jan 08, 2025 at 12:55:38PM +0100, Alice Ryhl wrote:
> On Wed, Jan 8, 2025 at 12:52 PM Greg Kroah-Hartman
> <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
> > > + /// Checks if property is present or not.
> > > + pub fn property_present(&self, name: &CString) -> bool {
> > > + // SAFETY: By the invariant of `CString`, `name` is null-terminated.
> > > + unsafe { bindings::device_property_present(self.as_raw() as *const _, name.as_ptr() as *const _) }
> >
> > I hate to ask, but how was this compiling if the const wasn't there
> > before? There's no type-checking happening here? If not, how are we
> > ever going to notice when function parameters change? If there is type
> > checking, how did this ever build without the const?
> >
> > confused,
>
> Rust auto-converts `*mut` pointers to `*const` when necessary.

Ah, so it's magic :)

thanks for the explaination.

greg k-h