Skip to content

Remove Copy and Clone implementation on sensitive structure#83

Merged
LuernOutOfOrder merged 8 commits intodevelopfrom
67-improve-memory-allocation-by-avoiding-too-much-copy-and-clone
Jan 19, 2026
Merged

Remove Copy and Clone implementation on sensitive structure#83
LuernOutOfOrder merged 8 commits intodevelopfrom
67-improve-memory-allocation-by-avoiding-too-much-copy-and-clone

Conversation

@LuernOutOfOrder
Copy link
Owner

This pull request refactors several hardware driver modules and their associated tests to improve code safety, clarity, and maintainability. The main changes include removing unnecessary Copy and Clone trait derivations from driver structs and enums, updating method signatures to use references for safer access, and refactoring test code to use constants and references instead of value copies. These changes help prevent accidental data duplication, clarify ownership semantics, and make the codebase more idiomatic and robust.

Trait and Derivation Simplification

  • Removed Copy and Clone trait derivations from various driver structs and enums, such as TrapFrame, CpuIntcDriver, CpuIntcHw, RiscVCpuIntc, SerialDeviceDriver, SerialDevice, Ns16550, Clint0, TimerType, TimerDeviceDriver, and TimerDevice. This enforces safer handling of these types and prevents unintended copying. [1] [2] [3] [4] [5] [6] [7] [8]

API and Method Signature Updates

  • Changed method signatures to return references instead of values for hardware device accessors, such as get_cpu_intc_core_id, timer_type, and get_primary_timer, improving safety and reducing unnecessary copies. [1] [2] [3]

Test Code Refactoring

  • Refactored test modules to use constant device definitions and references, replacing value copies with references and aligning with the new API signatures. This includes changes in CPU interrupt controller, serial, and timer subsystem tests. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Code Safety and Idiomatic Improvements

  • Updated internal logic to use references for accessing hardware pools and device arrays, reducing unsafe code and potential for bugs related to pointer dereferencing and data races. [1] [2] [3]

Version Update

  • Bumped the crate version from 0.3.0 to 0.3.1 in Cargo.toml to reflect the API and implementation changes.

@LuernOutOfOrder LuernOutOfOrder added this to the v0.3.5 milestone Jan 19, 2026
@LuernOutOfOrder LuernOutOfOrder self-assigned this Jan 19, 2026
@LuernOutOfOrder LuernOutOfOrder added the enhancement New feature or request label Jan 19, 2026
@LuernOutOfOrder LuernOutOfOrder merged commit a5a6822 into develop Jan 19, 2026
1 check passed
@LuernOutOfOrder LuernOutOfOrder deleted the 67-improve-memory-allocation-by-avoiding-too-much-copy-and-clone branch January 19, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant