rust: drm: ioctl: wrap `Device::from_raw` in an `unsafe` block
Subsystems (3)
PATCH 1/1 rust: drm: ioctl: wrap `Device::from_raw` in an `unsafe` block
declare_drm_ioctls! generates an unsafe extern "C" fn per ioctl. Inside
it, four unsafe operations are performed, while the call to Device::from_raw() relies on the enclosing unsafe fn body instead.
Both forms are legal, but the kernel builds all Rust code with -Dunsafe_op_in_unsafe_fn, which asks for the explicit block. The lint does not fire here because the macro is defined in the kernel crate and expanded in the
driver crates, and rustc suppresses lints for code coming from another crate's macro.
The patch is to wrap the call in an unsafe block, keeping the existing SAFETY comment. No functional change.
--- rust/kernel/drm/ioctl.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/drm/ioctl.rs +1 -1
@@ -152,7 +152,7 @@ macro_rules! declare_drm_ioctls {// dev/file match the current driver these ioctls are being declared // for, and it's not clear how to enforce this within the type system. let dev: &$crate::drm::device::Device <_ , $crate::drm::Ioctl > = - $crate::drm::device::Device ::from_raw (raw_dev); +unsafe { $crate::drm::device::Device ::from_raw (raw_dev) };// Type-inference anchor: the closure is never called but ties `dev`'s // type to `$func`'s first parameter, which the compiler cannot infer
--
2.43.0
Hello! some nits about the patch body
Quoted 9 lines · spidermana
declare_drm_ioctls!generates anunsafe extern "C" fnper ioctl. Inside
it, four unsafe operations are performed, while the call toDevice::from_raw()relies on the enclosingunsafe fnbody instead.Both forms are legal, but the kernel builds all Rust code with
-Dunsafe_op_in_unsafe_fn, which asks for the explicit block. The lint does not fire here because the macro is defined in thekernelcrate and expanded in the
driver crates, and rustc suppresses lints for code coming from another crate's macro.The patch is to wrap the call in an unsafe block, keeping the existing SAFETY comment. No functional change.
The lines in the message are usually wrapped at column 75 [1]. One thing I do is writing it in vim and if I see that the paragraph exceeds the limit, I put the cursor over it and type in normal mode gqip. This auto-wrapps it.
Quoted 2 lines
Signed-off-by spidermana <[email protected]>
Normally, a full legal name is used for signing patches [2].
If you are going to re-send the patch and nothing changes, you can use [PATCH RESEND] tag.
Hope that helps!
Regards,
Nicolás
[1] https://docs.kernel.org/process/submitting-patches.html#the-canonical-patch-format
[2] https://docs.kernel.org/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin