Arm Linux Kernel Hacks

rousalome.egloos.com

포토로그 Kernel Crash


통계 위젯 (화이트)

493
557
422263


[부록 C] 리눅스 커널 프로젝트에 기여하기: 패치 전달 - 커밋과 커밋 메시지 작성 부록

코드를 수정했으니 이제 패치를 커밋으로 생성해볼까요?

‘git add 파일_이름’ 명령어를 입력해 패치를 인덱스에 등록 합니다.   
root@raspberrypi:/home/pi/kernel_src/linux-next# git add mm/vmalloc.c 

다음 명령어를 입력해 커밋 메시지와 함께 커밋 인덱스를 추가합니다. 
root@raspberrypi:/home/pi/kernel_src/linux-next# git commit -m "mm/vmalloc.c: move 'area->pages' after if statement"
 [master 09c14a5] mm/vmalloc.c: move 'area->pages' after if statement
 1 file changed, 4 insertions(+), 2 deletions(-)

위 명령어에서 “커밋 메시지”는 다음과 같습니다.
"mm/vmalloc.c: move 'area->pages' after if statement"

이번에는 다음 명령어를 입력해 커밋 메시지에 ‘Signed-off-by: 이메일 주소’와 추가 커밋 메시지를 추가합니다. 
root@raspberrypi:/home/pi/kernel_src/linux-next# git commit --amend -s 

mm/vmalloc.c: move 'area->pages' after if statement

Signed-off-by: Austin Kim <austindh.kim@gmail.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
...
#
# Changes to be committed:
#   modified:   mm/vmalloc.c
#

'Signed-off-by'는 오픈 소스 라이센스 정책을 이해했으며 정책을 따르겠다는 의도로 추가하는 '도장'입니다. 만약 'Signed-off-by' 없이 패치 코드를 메인테이너에게 전달하면 'Signed-off-by'와 함께 다시 패치를 보내란 답장을 받을 확률이 높습니다.

이어서 'mm/vmalloc.c: move 'area->pages' after if statement' 제목 아랫 부분에 패치를 설명하는 메시지를 추가합니다.

01 mm/vmalloc.c: move 'area->pages' after if statement
02 
03 If !area->pages statement is true where memory allocation fails, area is
04 freed.
05 
06 In this case 'area->pages = pages' should not executed.  So move
07 'area->pages = pages' after if statement.
08
09 Signed-off-by: Austin Kim <austindh.kim@gmail.com>
10
 
커밋 메시지를 작성할 때는 패치의 내용을 명확하게 설명할 수 있는 문장을 써야 합니다. 여기서 주의해야 할 점은 패치의 내용을 너무 과장해 설명하면 안됩니다. 패치를 설명할 때 만약 ‘Fix Bug…", “Use-after-Free Fix” 등등의 표현을 쓰면 패치를 리뷰할 때 메인테이너나 다른 커널 개발자로부터 다음과 같은 질문을 받을 가능성이 높습니다.

    테스트 케이스는 무엇이냐?
    문제가 발생할 때 커널 로그를 알려줘라.

패치 리뷰를 할 때 이런 질문에 일일이 대답을 해줘야 하며 제대로 답변을 못하면 패치는 거절될 가능성이 높습니다.

이제 다음 명령어로 패치를 하나 생성해보겠습니다.
root@raspberrypi:/home/pi/kernel_src/linux-next# git format-patch -1
0001-mm-vmalloc.c-move-area-pages-after-if-statement.patch

‘git format-patch -1’는 최신 커밋 기준으로 1개 패치를 생성시키는 명령어입니다. 결과 다음 파일이 생성됐습니다. 
0001-mm-vmalloc.c-move-area-pages-after-if-statement.patch

이번에 위 파일을 열어 보겠습니다.
  1 From a7c761e9946132891664b2817984bf2466552130 Mon Sep 17 00:00:00 2001
  2 From: Austin Kim <austindh.kim@gmail.com>
  3 Date: Fri, 30 Aug 2019 12:57:16 2019 +0900 
  4 Subject: [PATCH] mm/vmalloc.c: move 'area->pages' after if statement
  5
  6 If !area->pages statement is true where memory allocation fails, area is
  7 freed.
  8
  9 In this case 'area->pages = pages' should not executed.  So move
 10 'area->pages = pages' after if statement.
 11
 12 Signed-off-by: Austin Kim <austindh.kim@gmail.com>
 13 ---
 14  mm/vmalloc.c | 6 ++++--
 15  1 file changed, 4 insertions(+), 2 deletions(-)
 16
 17 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
 18 index e66e7ff..0471c78 100644
 19 --- a/mm/vmalloc.c
 20 +++ b/mm/vmalloc.c
 21 @@ -2416,13 +2416,15 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
 22     } else {
 23         pages = kmalloc_node(array_size, nested_gfp, node);
 24     }
 25 -   area->pages = pages;
 26 -   if (!area->pages) {
 27 +
 28 +   if (!pages) {
 29         remove_vm_area(area->addr);
 30         kfree(area);
 31         return NULL;
 32     }
 33
 34 +   area->pages = pages;
 35 +
 36     for (i = 0; i < area->nr_pages; i++) {
 37         struct page *page;
 38
 39 --
 40 2.6.2
 41


"혹시 궁금한 점이 있으면 댓글로 질문 남겨주세요. 아는 한 성실히 답변 올려드리겠습니다!" 

Thanks,
Austin Kim(austindh.kim@gmail.com)


[부록 A] GCC 지시어
   * inline    
   * noinline    
   * __noreturn   
   * unused   
[부록 B] 리눅스 커널 실력을 키우는 방법
[부록 C] 리눅스 커널 프로젝트에 기여하기  
C.1 리눅스 커널 오픈소스 프로젝트 소개 
   * 용어  
C.2 설정 방법 
C.3 패치 코드를 작성한 후 이메일로 보내기  
C.5 리눅스 커널 오픈소스 프로젝트로 얻는 지식 


# Reference: For more information on 'Linux Kernel';

디버깅을 통해 배우는 리눅스 커널의 구조와 원리. 1

디버깅을 통해 배우는 리눅스 커널의 구조와 원리. 2


 



핑백

덧글

댓글 입력 영역