Refactor duplicated code across kernel subsystems - #140
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor duplicated code for improved maintainability
Refactor duplicated code across kernel subsystems
Oct 29, 2025
iamantoinev
marked this pull request as ready for review
October 29, 2025 09:34
iamantoinev
approved these changes
Oct 29, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR contains several refactoring improvements and bug fixes across the kernel codebase, focusing on code deduplication, fixing logical errors, and improving maintainability.
- Fixed a critical logical operator bug in
get_level()that prevented proper level parsing - Refactored duplicated code in PIC IRQ mask operations and paging table lookups into helper functions
- Improved command handling architecture by replacing if-else chains with a table-driven approach
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| kernel/src/tty/vprintf.c | Simplified putnbr_base() to delegate to putnbr_base_unsigned() after handling negative sign |
| kernel/src/tty/printk.c | Fixed logical OR to AND in get_level() condition |
| kernel/src/pic.c | Refactored pic_enable_irq() and pic_disable_irq() to share common logic via pic_set_irq_mask() |
| kernel/src/memory/paging.c | Extracted duplicated page table lookup logic into get_page_table() helper function |
| kernel/src/command/handle.c | Refactored command dispatch from if-else chain to table-driven approach |
| kernel/src/command/halt.c | Extracted halt command implementation into dedicated file |
| kernel/include/command.h | Added cmd_halt() function declaration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Neffi42
approved these changes
Oct 29, 2025
Refactor duplicated code in command handler and printf functions Co-authored-by: antoineverin <24255551+antoineverin@users.noreply.github.com> Refactor page table access duplication in paging.c Co-authored-by: antoineverin <24255551+antoineverin@users.noreply.github.com> Refactor PIC IRQ mask functions to eliminate duplication Co-authored-by: antoineverin <24255551+antoineverin@users.noreply.github.com> Final review - all refactoring complete Co-authored-by: antoineverin <24255551+antoineverin@users.noreply.github.com> Delete _codeql_detected_source_root Signed-off-by: Antoine Verin <24255551+antoineverin@users.noreply.github.com> apply ql sugestion
iamantoinev
force-pushed
the
copilot/refactor-duplicated-code
branch
from
October 29, 2025 13:37
6b37d0b to
b574970
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Eliminates ~45 lines of duplicated logic across command handling, memory management, and I/O subsystems.
Changes
Command dispatch - Replaced if-else strcmp chains with table-driven lookup:
Printf base conversion -
putnbr_base()now delegates toputnbr_base_unsigned()after sign handling, eliminating 10 lines of recursive duplicationPage table access - Extracted
get_page_table()to remove repeatedrecursive_active()checks acrossmap_page(),unmap_page(), andget_phys_addr()PIC IRQ masking - Unified
pic_enable_irq()andpic_disable_irq()viapic_set_irq_mask(bool enable)helperBug fix - Corrected
get_level()in printk.c:c >= '0' || c <= '7'→c >= '0' && c <= '7'Stats
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.