# Linux patch 心得 這篇文章是用來記錄我貢獻一行程式碼給 `Linux` 的心得,裡面包含 patch 的流程還有一些細節。 [commit 在這](https://lore.kernel.org/lkml/20240305165652.18842-1-harry021633@gmail.com/) ### 流程 流程可以參考這兩篇文章,他們寫得挺詳細的 - [提交第一份 Patch 到 Linux Kernel](https://hackmd.io/@steven1lung/submitting-patches) - [第一次給Linux Kernel發patch](https://hackmd.io/@rhythm/BkjJeugOv) 在提交 patch 之前一定要注意的是簽名不能用假名,一定要用真名。在 [Documentation/process/1.Intro.rst](https://github.com/torvalds/linux/blob/master/Documentation/process/1.Intro.rst) 中有提到: > It is imperative that all code contributed to the kernel be legitimately free software. For that reason, code from anonymous (or pseudonymous) contributors will not be accepted. All contributors are required to "sign off" on their code, stating that the code can be distributed with the kernel under the GPL. 當你因為這個原因要進行調整之後,請調整 `.gitconfig` 的名字 ``` git config --global user.name "REAL NAME" ``` 之後再用 [`smtp`](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol) 寄出去 寄出去的信會長這樣 ``` [PATCH] i2c: remove redundant condition I2C_M_RD is defined as 1 and `flag & I2C_M_RD` is one or zero no need one more condition to get the value Signed-off-by: Hsin-Yu.Chen <harry021633@gmail.com> --- include/linux/i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 652ecb7abeda..363dde9ef94f 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -931,7 +931,7 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap) static inline u8 i2c_8bit_addr_from_msg(const struct i2c_msg *msg) { - return (msg->addr << 1) | (msg->flags & I2C_M_RD ? 1 : 0); + return (msg->addr << 1) | (msg->flags & I2C_M_RD); } u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold); -- ``` 必須要是純文字檔,不然你就會收到 linux 的拒絕信 ``` HTML message rejected: Re: [PATCH] i2c: remove redundant condition ``` 當你的 commit 被接受之後也會收到信 ``` * linux-i2c: i2c: remove redundant condition - http://patchwork.ozlabs.org/project/linux-i2c/patch/20240306041900.22885-1-harry021633@gmail.com/ - for: Linux I2C development was: New now: Accepted ``` ### 心得 這篇文章主要是記錄第一次發 patch 的心情和 patch 的小細節。 會想要提交這個 commit 主要是因為上班的時候看到 `i2c` 沒有處理 `endian` 調換的問題。但是因為沒有這方面的經驗,又看到一個 API 有多餘的判斷式,才想說拿這個比較有把握可以被接受的試試看。 結果 patch 出去之後等了三個禮拜沒有回應,當我想寄第二封信的時候,就收到 reviewer 的回應了,reviewer 一開始就看到簽名的問題就有提醒我,改完簽名就收到 accept 啦