diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs index 080dedb5d5d9..90d364ab3bf2 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -137,30 +137,9 @@ pub fn build( ) })?; - const TABLE: bindings::block_device_operations = bindings::block_device_operations { - submit_bio: None, - open: None, - release: None, - ioctl: None, - compat_ioctl: None, - check_events: None, - unlock_native_capacity: None, - getgeo: None, - set_read_only: None, - swap_slot_free_notify: None, - report_zones: None, - devnode: None, - alternative_gpt_sector: None, - get_unique_id: None, - // TODO: Set to `THIS_MODULE`. - owner: core::ptr::null_mut(), - pr_ops: core::ptr::null_mut(), - free_disk: None, - poll_bio: None, - }; - - // SAFETY: `gendisk` is a valid pointer as we initialized it above - unsafe { (*gendisk).fops = &TABLE }; + // SAFETY: `gendisk` is a valid pointer. We have exclusive access, + // since the disk is not added to the VFS yet. + unsafe { (*gendisk).fops = &GenDisk::::VTABLE }; let cleanup_failure = ScopeGuard::new_with_data((gendisk, data), |(gendisk, data)| { // SAFETY: `gendisk` came from `__blk_mq_alloc_disk()` above and @@ -223,6 +202,13 @@ pub struct GenDisk { gendisk: *mut bindings::gendisk, } +impl GenDisk { + const VTABLE: bindings::block_device_operations = bindings::block_device_operations { + owner: crate::module::this_module::().as_ptr(), + ..pin_init::zeroed() + }; +} + // SAFETY: `GenDisk` is an owned pointer to a `struct gendisk` and an `Arc` to a // `TagSet`. It is safe to send this to other threads as long as these two are `Send`. unsafe impl Send for GenDisk