|
|
Subscribe / Log in / New account

A GPIO driver in Rust

A GPIO driver in Rust

Posted Jul 20, 2021 2:12 UTC (Tue) by mathstuf (subscriber, #69389)
In reply to: A GPIO driver in Rust by tialaramex
Parent article: A GPIO driver in Rust

The situation is answered in this message[1]:

> 2. The extra check we have here is because of a feature that the C code doesn't
> have: revocable resources. If we didn't want to have this, we could do say
> `data.base.writeb(...)` directly, but then we could have situations where `base`
> is used after the device was removed. By having these checks we guarantee that
> anyone can hold a reference to device state, but they can no longer use hw
> resources after the device is removed.

So it does seem to be "Rust has a few patterns factored out; C has other behaviors/assumptions factored out" kind of difference. It would seem that the C code is "hold it this way and you'll be fine"[2] whereas Rust is more "you have a reference to me, so I must keep myself safe".

[1]https://lore.kernel.org/ksummit/YPW%2FLNwxwEW4h0GM@google...
[2]The bad case being someone stuffing a pointer to the device and calling things directly rather than through the proper API channels.


(Log in to post comments)

A GPIO driver in Rust

Posted Jul 20, 2021 3:45 UTC (Tue) by roc (subscriber, #30627) [Link]

Thank you!

A GPIO driver in Rust

Posted Jul 20, 2021 14:29 UTC (Tue) by xav (subscriber, #18536) [Link]

> It would seem that the C code is "hold it this way and you'll be fine"[2] whereas Rust is more "you have a reference to me, so I must keep myself safe".

That would match my experience with C and Rust very nicely.


Copyright © 2023, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds