rust: serdev: use ThisModule::as_ptr() instead of field access
Subsystems (4)
Danilo Krummrich
maintainerPATCH 1/1 rust: serdev: use ThisModule::as_ptr() instead of field access
The THIS_MODULE series [1] applied to rust-next moved ThisModule from lib.rs into a module.rs submodule, making the tuple struct field private outside the module. This breaks the module.0 field access in serdev in driver-core-next.
Update the call to __serdev_device_driver_register() to use the public module.as_ptr() accessor to fix the build.
--- rust/kernel/serdev.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/serdev.rs +1 -1
@@ -87,7 +87,7 @@ unsafe fn register( }// SAFETY: `sdrv` is guaranteed to be a valid `DriverType`. -to_result (unsafe { bindings::__serdev_device_driver_register (sdrv.get (), module.0 ) }) +to_result (unsafe { bindings::__serdev_device_driver_register (sdrv.get (), module.as_ptr ()) }) }unsafe fn unregister (sdrv: &Opaque <Self ::DriverType >) {
base-commit: 8364d0e36cbbdfe9adb65a170a70cbe3cdb02ff9
Signature · 1 line
2.55.0
Quoted 7 lines · Danilo Krummrich
The
THIS_MODULEseries [1] applied to rust-next moved ThisModule fromlib.rsinto amodule.rssubmodule, making the tuple struct field private outside the module. This breaks the module.0 field access in serdev in driver-core-next.Update the call to
__serdev_device_driver_register()to use the publicmodule.as_ptr()accessor to fix the build.
I encounter 2 errors when building with both driver-core-next and rust- next
error[E0616]: field 0 of struct module::ThisModule is private
--> rust/kernel/serdev.rs:90:89
|
90 | to_result(unsafe {bindings::__serdev_device_driver_register(sdrv.get(), module.0) })
|
^ private field
error[E0599]: no method named __pinned_init found for associated type `impl pin_init::PinInit<<T as serdev::Driver>::Data<'_>, error::Error>
+ '_` in the current scope
--> rust/kernel/serdev.rs:200:40
|
200 | let result = unsafe {
data.__pinned_init(driver.as_mut_ptr()) };
| ^^^^^^^^^^^^^ method not
found in impl pin_init::PinInit<<T as serdev::Driver>::Data<'_>, error::Error> + '_
error: aborting due to 2 previous errors
Quoted 22 lines
Signed-off-by Danilo Krummrich <[email protected]>--- rust/kernel/serdev.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)rust/kernel/serdev.rs +1
-1@@ -87,7 +87,7 @@ unsafe fn register( }// SAFETY: `sdrv` is guaranteed to be a valid `DriverType`. -to_result (unsafe { bindings::__serdev_device_driver_register (sdrv.get (), module.0 ) }) +to_result (unsafe { bindings::__serdev_device_driver_register (sdrv.get (), module.as_ptr ()) }) }unsafe fn unregister (sdrv: &Opaque <Self ::DriverType >) {
Quoted 1 line
base-commit:
8364d0e36cbbdfe9adb65a170a70cbe3cdb02ff9
The first error disappears with this patch.
Should I send a patch regarding the 2. error?
It seems the PinInit::__pinned_init function is not only deprecated, but also behind the #[cfg(not(kernel))] flag, which causes the error.
Thanks
- Markus Probst
Gary Guo
reviewerQuoted 34 lines · Markus Probst
Quoted 7 lines · Danilo Krummrich
The
THIS_MODULEseries [1] applied to rust-next moved ThisModule fromlib.rsinto amodule.rssubmodule, making the tuple struct field private outside the module. This breaks the module.0 field access in serdev in driver-core-next.Update the call to
__serdev_device_driver_register()to use the publicmodule.as_ptr()accessor to fix the build.I encounter 2 errors when building with both driver-core-next and rust- next
error[E0616]: field
0of structmodule::ThisModuleis private
-->rust/kernel/serdev.rs:90:89
|
90 | to_result(unsafe {bindings::__serdev_device_driver_register(sdrv.get(), module.0)})
|
^ private fielderror[E0599]: no method named
__pinned_initfound for associated type `impl pin_init::PinInit<<T as serdev::Driver>::Data<'_>,error::Error>
+ '_` in the current scope
-->rust/kernel/serdev.rs:200:40|200 | let result = unsafe {
data.__pinned_init(driver.as_mut_ptr()) };
| ^^^^^^^^^^^^^ method not
found inimpl pin_init::PinInit<<T as serdev::Driver>::Data<'_>, error::Error> + '_error: aborting due to 2 previous errors
[snip]
Quoted 7 lines
Should I send a patch regarding the 2. error?
It seems the
PinInit::__pinned_initfunction is not only deprecated, but also behind the#[cfg(not(kernel))]flag, which causes the error.Thanks
- Markus Probst
This is a semantic conflict that cannot be solved on a single tree and has to be done on the merge commit.
A resolution is already on linux-next, see
https://lore.kernel.org/rust-for-linux/[email protected]/
Best,
Gary
Danilo Krummrich
maintainerQuoted 1 line · Markus Probst
Should I send a patch regarding the 2. error?
The second one can't be fixed with a patch in either of the trees, as it is a real merge conflict.
This one is only fixable in the driver-core tree, since as_ptr() is a preexisting method.
Quoted 11 lines · Danilo Krummrich
The
THIS_MODULEseries [1] applied to rust-next moved ThisModule fromlib.rsinto amodule.rssubmodule, making the tuple struct field private outside the module. This breaks the module.0 field access in serdev in driver-core-next.Update the call to
__serdev_device_driver_register()to use the publicmodule.as_ptr()accessor to fix the build.
Quoted 3 lines
--- rust/kernel/serdev.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line · Danilo Krummrich
[PATCH] rust: serdev: use
ThisModule::as_ptr()instead of field access
Applied, thanks!
Branch: driver-core-next
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
[1/1] rust: serdev: use ThisModule::as_ptr() instead of field access
commit: ddca0cd80096
The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).
The patch is queued up for the upcoming merge window for the next major kernel release.