On Wed, 11 Dec 2024, Lee Jones wrote: > On Tue, 10 Dec 2024, Alice Ryhl wrote: > > > Providing access to the underlying `struct miscdevice` is useful for > > various reasons. For example, this allows you access the miscdevice's > > internal `struct device` for use with the `dev_*` printing macros. > > > > Note that since the underlying `struct miscdevice` could get freed at > > any point after the fops->open() call (if misc_deregister is called), > > only the open call is given access to it. To use `dev_*` printing macros > > from other fops hooks, take a refcount on `miscdevice->this_device` to > > keep it alive. See the linked thread for further discussion on the > > lifetime of `struct miscdevice`. > > > > Link: https://lore.kernel.org/r/2024120951-botanist-exhale-4845@gregkh > > Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> > > --- > > rust/kernel/miscdevice.rs | 30 ++++++++++++++++++++++-------- > > 1 file changed, 22 insertions(+), 8 deletions(-) > > Reviewed-by: Lee Jones <lee@xxxxxxxxxx> Tested-by: Lee Jones <lee@xxxxxxxxxx> -- Lee Jones [李琼斯]