Skip to content

Conversation

@masnagam
Copy link

@masnagam masnagam commented Jul 20, 2025

モジュールの初期化および終了関数にそれぞれ __init__exit を指定した.これらマクロを使用していなくても大きな問題は発生しないと考えられるが,一般的な作法として追加した.

これらマクロの説明は以下を参照:

ビルド確認

archlinxイメージを使用

$ docker run --rm -it -v $(pwd):/px4_drv archlinux
[root@1245c254444d px4_drv]# uname -a
Linux 1245c254444d 6.15.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 17 Jul 2025 21:05:29 +0000 x86_64 GNU/Linux

以下を実行

pacman -Sy --noconfirm dkms gcc linux-headers make
cp -a ./ /usr/src/px4_drv-0.5.4
dkms add px4_drv/0.5.4
dkms install px4_drv/0.5.4
find /lib/modules -name px4_drv.ko

TODO

ビルド時に以下のメッセージが表示される.

Deprecated feature: CLEAN (/var/lib/dkms/px4_drv/0.5.4/source/dkms.conf)

以下の修正でCLEANはdkmsから削除された:

Summary by CodeRabbit

  • リファクタ
    • 新しいカーネルバージョン(6.15.4以降)に対応するため、初期化およびクリーンアップ処理の内部実装を調整しました。動作や機能には変更ありません。

モジュールの初期化および終了関数にそれぞれ `__init` と `__exit` を指定
した.これらマクロを使用していなくても大きな問題は発生しないと考えられ
るが,一般的な作法として追加した.

これらマクロの説明は以下を参照:

* https://tldp.org/LDP/lkmpg/2.4/html/x281.htm
* https://fastbitlab.com/linux-device-driver-programming-lecture-18-__init-and-__exit-macros/
* https://shnoh171.github.io/linux%20kernel/2019/09/01/linux-kernel-module-basics.html
@coderabbitai
Copy link

coderabbitai bot commented Jul 20, 2025

Walkthrough

driver/driver_module.c の初期化関数とクリーンアップ関数に、カーネルバージョン 6.15.4 以上の場合のみ __init および __exit マクロを付与するよう変更されました。関数名や制御フロー自体は変更されていません。

Changes

ファイル 変更概要
driver/driver_module.c カーネル6.15.4以上で初期化関数に__init、クリーンアップ関数に__exitマクロを付与。関数名やロジックは変更なし。

Poem

うさぎがコードにぴょんと跳ね、
マクロを添えて新たな種、
カーネル見守り静かに待つ、
初期化も終了も、
うさぎのしっぽでふわり包む。
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ac1fca and fe259b5.

📒 Files selected for processing (1)
  • driver/driver_module.c (2 hunks)
🔇 Additional comments (1)
driver/driver_module.c (1)

19-24: バージョン分岐が過剰です ― module_init / module_exit__init / __exit は古いカーネルでも利用可能

__init / __exitmodule_init / module_exit も 2.6 系から既に存在しており、6.15 以降に限定する理由はありません。
現状の分岐では

  • 6.15 未満のカーネルで “グローバル記号 init_module / cleanup_module” を公開する旧式 API を使う
  • 6.15 以上で “静的関数 + module_init/module_exit” を使う

という二重実装になり、保守コストが上がります。どのバージョンでも後者(静的関数 + マクロ)のみで問題なく動作します。

提案 diff(分岐を削除し、シンプルに統一):

-#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,15,4)
-static int __init m_init(void)
-#else
-int init_module(void)
-#endif
+static int __init m_init(void)

 ...

-#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,15,4)
-static void __exit m_cleanup(void)
-#else
-void cleanup_module(void)
-#endif
+static void __exit m_cleanup(void)

 ...

-#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,15,4)
 module_init(m_init);
 module_exit(m_cleanup);
-#endif

これで全カーネルで同一コードパスとなり、不要な条件分岐・重複が排除できます。
互換性に懸念があれば alias マクロで旧シンボルを残す手も取れますが、通常は不要です。
[ suggest_essential_refactor ]

Also applies to: 55-67

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tsukumijima
Copy link
Owner

ありがとうございます!

@tsukumijima tsukumijima merged commit b4a6f9a into tsukumijima:develop Jul 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants