1.. SPDX-License-Identifier: GPL-2.0
2
3.. include:: ../disclaimer-zh_TW.rst
4
5:Original: Documentation/process/coding-style.rst
6
7.. _tw_codingstyle:
8
9:������:
10 - ������ Zhang Le <r0bertz@gentoo.org>
11 - Andy Deng <theandy.deng@gmail.com>
12 - ��������� <bobwxc@email.cn>
13
14:������:
15 - ������ Wang Cong <xiyou.wangcong@gmail.com>
16 - wheelz <kernel.zeng@gmail.com>
17 - ��������� Xudong Guan <xudong.guan@gmail.com>
18 - Li Zefan <lizf@cn.fujitsu.com>
19 - Wang Chen <wangchen@cn.fujitsu.com>
20 - Hu Haowen <2023002089@link.tyut.edu.cn>
21
22Linux ������������������
23==================
24
25��������������������������������������� linux ���������������������������������������������������������������
26������������������������������������������������������������������������������������������������������������������
27��������������������������������������������������������������������� (���������������) ������������������������
28������������������
29
30��������������������������������� GNU ���������������������������������������������������������������������������
31���������������������
32
33������������������������������������
34
35
361) ������
37-------
38
39������������ 8 ������������������������������ 8 ��������������������������������������������������� 4 (������
402���) ��������������������������������������������������������������� 3���
41
42������������������������������������������������������������������������������������������������������������������
43������������������ 20 ���������������������������������������������������������������������������������
44
45��������������������������� 8 ������������������������������������������������������������ 80 ������������������
46��������������������������������������������������������������������������������� 3 ������������������������������
47������������������������������������������������������������������������
48
49���������������8 ������������������������������������������������������������������������������������������������
50������������������������������������������������������
51
52��� switch ��������������������������������������������������� ``switch`` ������������������ ``case``
53������������������������������������ ``������������`` ``case`` ������������������
54
55.. code-block:: c
56
57	switch (suffix) {
58	case 'G':
59	case 'g':
60		mem <<= 30;
61		break;
62	case 'M':
63	case 'm':
64		mem <<= 20;
65		break;
66	case 'K':
67	case 'k':
68		mem <<= 10;
69		fallthrough;
70	default:
71		break;
72	}
73
74���������������������������������������������������������������������������
75
76.. code-block:: c
77
78	if (condition) do_this;
79	  do_something_everytime;
80
81���������������������������������������������
82
83.. code-block:: c
84
85	if (condition)
86		do_this(), do_that();
87
88���������������������������������
89
90.. code-block:: c
91
92	if (condition) {
93		do_this();
94		do_that();
95	}
96
97������������������������������������������������������������������������������������������������������������������
98���������������
99
100������������������������ Kconfig ������������������������������������������������������������������������������
101������
102
103���������������������������������������������������������
104
105
1062) ������������������������������
107-----------------------
108
109������������������������������������������������������������������������������������������������������
110
111������������������������������ 80 ������������������������������������������������
112
113������ 80 ��������������������������������������������������������� 80 ���������������������������������������
114������������������
115
116������������������������������������������������������������������������������������������������������������������������
117
118���������������������������������������������������������
119
120��������������������������������������������������������������� printk ������������������������
121��������������� grep���
122
123
1243) ���������������������������
125---------------------
126
127C ���������������������������������������������������������������������������������������������������������������
128��������������������������������������������������������������������������� Kernighan ��� Ritchie ������
129������������������������������������������������������������������������������������������������
130
131.. code-block:: c
132
133	if (x is true) {
134		we do y
135	}
136
137��������������������������������������� (if, switch, for, while, do)������������
138
139.. code-block:: c
140
141	switch (action) {
142	case KOBJ_ADD:
143		return "add";
144	case KOBJ_REMOVE:
145		return "remove";
146	case KOBJ_CHANGE:
147		return "change";
148	default:
149		return NULL;
150	}
151
152������������������������������������������������������������������������������������������������������������
153
154.. code-block:: c
155
156	int function(int x)
157	{
158		body of function
159	}
160
161���������������������������������������������������������������������������������������������������������������
162��������� (a) K&R ��� **���������** ������ (b) K&R ���������������������������������������������������
163������ (C ������������������������)���
164
165��������������������������������������������������������������������������������������������������������� do ���
166��������� ``while`` ������ if ������������ ``else`` ���������������
167
168.. code-block:: c
169
170	do {
171		body of do-loop
172	} while (condition);
173
174���
175
176.. code-block:: c
177
178	if (x == y) {
179		..
180	} else if (x > y) {
181		...
182	} else {
183		....
184	}
185
186���������K&R���
187
188������������������������������������������������������ (���������������������) ���������������������������������
189��������������������������������������������������������������������������� (������ 25 ������������������)������
190������������������������������������������
191
192���������������������������������������������������������������������������
193
194.. code-block:: c
195
196	if (condition)
197		action();
198
199���
200
201.. code-block:: c
202
203	if (condition)
204		do_this();
205	else
206		do_that();
207
208������������������������������������������������������������������������������������������������������������
209
210.. code-block:: c
211
212	if (condition) {
213		do_this();
214		do_that();
215	} else {
216		otherwise();
217	}
218
2193.1) ������
220*********
221
222Linux ��������������������������� (������) ���������������������������������������������(���������) ���������
223������������������������������������������������ sizeof, typeof, alignof ��� __attribute__������
224������������������������������������������������ (��������� Linux ���������������������������������������������
225��� C ��������������������������������������������� ``struct fileinfo info;`` ���������������
226``sizeof info``)���
227
228���������������������������������������������::
229
230	if, switch, case, for, do, while
231
232��������������� sizeof, typeof, alignof ������ __attribute__ ���������������������������������
233���������
234
235.. code-block:: c
236
237	s = sizeof(struct file);
238
239��������������������������������������������������������������� **������** ���
240
241.. code-block:: c
242
243	s = sizeof( struct file );
244
245������������������������������������������������������������ ``*`` ���������������������������������������������
246������������������������������������������������������
247
248.. code-block:: c
249
250	char *linux_banner;
251	unsigned long long memparse(char *ptr, char **retptr);
252	char *match_strdup(substring_t *s);
253
254������������������������������������������������������������������������������������������������::
255
256	=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=  ?  :
257
258���������������������������������������::
259
260	&  *  +  -  ~  !  sizeof  typeof  alignof  __attribute__  defined
261
262���������������������������������������������������::
263
264	++  --
265
266���������������������������������������������������::
267
268	++  --
269
270``.`` ��� ``->`` ���������������������������������������������
271
272������������������������������������������������������������������������������������������������������������������
273������������������������������������������������������������������������������������������������������������������
274������������������������������������������������������������������������������������������������������������������
275������������������
276
277��� git ���������������������������������������������������������������������������������������������������������
278������������������������������������������������������������������������������������������������������������������
279������������
280
281
2824) ������
283-------
284
285C ������������������������������������������������������������ Modula-2 ��� Pascal ������������������
286C ������������������������ ThisVariableIsATemporaryCounter ������������������������C ������������
287������������������ ``tmp`` ������������������������������������������������������������������������
288
289������������������������������������������������������������������������������������������������������������������
290��������������������������������� ``foo`` ���������������������������������
291
292������������ (������������ **������** ������������������������������) ������������������������������������������
293���������������������������������������������������������������������������������������������
294``count_active_users()`` ������������������������������������������ ``cntuser()`` ���
295
296��������������������������������� (���������������������������) ���������������������������������������������������
297������������������������������������������������������������������������������
298
299������������������������������������������������������������������������������������������������������������������
300��������������������������� ``i`` ��������� ``loop_counter`` ������������������������������������������
301��������������������������� ``tmp`` ������������������������������������������������
302
303������������������������������������������������������������������������������������������������������������������
304������������������������ (������)���
305
306���������������������������������������������������master/slave���������������������master���������slave������
307������blacklist/whitelist������
308
309���master/slave���������������������
310    '{primary,main} / {secondary,replica,subordinate}'
311    '{initiator,requester} / {target,responder}'
312    '{controller,host} / {device,worker,proxy}'
313    'leader/follower'
314    'director/performer'
315
316���blacklist/whitelist���������������������
317    'denylist/allowlist'
318    'blocklist/passlist'
319
320������������������������������������������������������ABI/API���������������������������2020���������������
321���������������������������������������������������������������������������������������������������������������
322���������������
323
324.. warning::
325	���������������������������������������������������������������������������������������
326
3275) Typedef
328----------
329
330������������������ ``vps_t`` ������������������
331
332��������������������������� typedef ��������� **������** ������������������������������
333
334.. code-block:: c
335
336	vps_t a;
337
338���������������������������
339
340������������������������
341
342.. code-block:: c
343
344	struct virtual_container *a;
345
346������������ ``a`` ���������������
347
348��������������� typedef ``������������������`` ���������������������������������������������������������������
349
350 (a) ������������������������ (������������������������������ typedef ��� **������** ���������������������
351     ���������)���
352
353     ��������� ``pte_t`` ������������������������������������������������������������������������
354
355     .. note::
356
357       ������������������������������������������������������������������ pte_t ���������������������������
358       ���������������������������������������������������
359
360 (b) ������������������������������������������������������ **������** ��������������� ``int`` ������
361     ``long`` ������������
362
363     u8/u16/u32 ������������������������ typedef������������������������������ (d) ������������������
364
365     .. note::
366
367       ��������������������������������������������������������� ``unsigned long`` ���������������������
368
369	typedef unsigned long myflags_t;
370
371     ������������������������������������������������������������������������������������ ``unsigned int``
372     ������������������������������ ``unsigned long`` ������������������������������������������
373     typedef���
374
375 (c) ������������ sparse ������������������������ **���** ������������������������������������
376
377 (d) ��������� C99 ������������������������������������������������������
378
379     ��������������������������������������������������������� ``uint32_t`` ������������������������������
380     ���������������������������������������
381
382     ���������Linux ��������������������������������� ``u8/u16/u32/u64`` ���������������������������
383     ������������������������������������������������������������������������������������������������������
384
385     ������������������������������������������������������������������������������������������������������������
386     ������
387
388 (e) ���������������������������������������������
389
390     ��������������������������������������������������������������� C99 ������������������������������������
391     ``u32`` ��������������������������������������������������������������������������� __u32 ���������
392     ������������
393
394������������������������������������������������������ **������������** ������ typedef���������������������
395���������������������������������������������
396
397������������������������������������������������������������������������������������������������������������������
398��������������������� typedef���
399
400
4016) ������
402-------
403
404��������������������������������������������������������������������������������������������������������� (������
405��������� ISO/ANSI ��������������� 80x24)���������������������������������������������
406
407������������������������������������������������������������������������������������������������������������������
408������������������������������������ (������������) ��� case ������������������������������������������ case
409���������������������������������������������������������������������������������
410
411������������������������������������������������������������������������������������������������������������������
412������������������������������������������������������������������������������������������������������������������
413������������������������������������ (���������������������������������������������������������������������������
414���������������������������������������������������������������������������)
415
416��������������������������������������������������������������������������������� 5���10 ������������������������
417������������������������������������������������������������������������������������������������������������������
418��������������� 7 ������������������������������������������������������������������������������������������������
419������������������ 2 ������������������������������
420
421��������������������������������������������������������������������������������������������� **EXPORT** ���
422������������������������������������������������������
423
424.. code-block:: c
425
426	int system_is_up(void)
427	{
428		return system_state == SYSTEM_RUNNING;
429	}
430	EXPORT_SYMBOL(system_is_up);
431
4326.1) ������������
433*************
434
435������������������������������������������������������������������ C ���������������������������������������
436Linux ������������������������������������������������������������������������������������������������������
437
438������������������������������ ``extern`` ������������������������������������������������������������������
439������������
440
441������������������������������ `������������������ <https://lore.kernel.org/mm-commits/CAHk-=wiOCLRny5aifWNhr621kYrJwhfURsa0vFPeUEm8mF0ufg@mail.gmail.com/>`_ ���
442������������������������::
443
444 __init void * __must_check action(enum magic value, size_t size, u8 count,
445				   char *fmt, ...) __printf(4, 5) __malloc;
446
447���������������������������������������
448
449- ������������������������ ``static __always_inline`` ��������� ``__always_inline``
450  ��������������������������������������� ``inline`` ���
451- ������������������������������ ``__init`` ������������������������������ ``__cold`` ���
452- ������������������������ ``void *`` ���
453- ������������������������������ ``__must_check`` ���
454- ��������������������� ``action`` ���
455- ������������������������ ``(enum magic value, size_t size, u8 count, char *fmt, ...)`` ���
456  ������������������������������
457- ������������������������������ ``__printf(4, 5)`` ���
458- ������������������������������ ``__malloc`` ���
459
460������������������������ **������** ���������������������������������������������������������������������������
461��������������������������������������������������������������������������������������������������� **������**
462��������������������������������� ``__printf(4, 5)`` ���������������������������::
463
464 static __always_inline __init __printf(4, 5) void * __must_check action(enum magic value,
465		size_t size, u8 count, char *fmt, ...) __malloc
466 {
467	...
468 }
469
4707) ���������������������������
471---------------------
472
473��������������������������������������������� goto ������������������������������������������������������������
474���������������������������������
475
476���������������������������������������������������������������������������������������������goto ���������������
477������������������������������������������������������ return ���������
478
479������������������������ goto ��������������������������������������������� goto ��������� ``buffer``,
480������������������������������ ``out_free_buffer:`` ������������������ ``err1:`` ��� ``err2:``
481���������GW_BASIC ������������������������������������������ (���������) ������������������������������������
482���������������������������������������������������
483
484������ goto ���������������
485
486- ������������������������������������
487- ������������������
488- ������������������������������������������������������������������������
489- ��������������������������������������������� ;)
490
491.. code-block:: c
492
493	int fun(int a)
494	{
495		int result = 0;
496		char *buffer;
497
498		buffer = kmalloc(SIZE, GFP_KERNEL);
499		if (!buffer)
500			return -ENOMEM;
501
502		if (condition1) {
503			while (loop1) {
504				...
505			}
506			result = 1;
507			goto out_free_buffer;
508		}
509		...
510	out_free_buffer:
511		kfree(buffer);
512		return result;
513	}
514
515������������������������������������ ``��� err ������`` ������������������
516
517.. code-block:: c
518
519	err:
520		kfree(foo->bar);
521		kfree(foo);
522		return ret;
523
524��������������������������������������������������� ``foo`` ��� NULL���������������������������������������
525��������������������� ``err_free_bar:`` ��� ``err_free_foo:`` ������������������������
526
527.. code-block:: c
528
529	err_free_bar:
530		kfree(foo->bar);
531	err_free_foo:
532		kfree(foo);
533		return ret;
534
535���������������������������������������������������������������������
536
537
5388) ������
539-------
540
541������������������������������������������������������������������������������������������������������������������
542������������������������������������������������������������������������������������������������������������
543
544���������������������������������������������������������������������������������������������������������
545������������������������������������������������������������������������������������������������������������������
546��������������������������������������������������������������������������������������������� (������������) ���
547������������������������������������������������������������������������������������������������������������������
548���������������������������������������������
549
550��������������� API ��������������������� kernel-doc ���������������
551Documentation/translations/zh_CN/doc-guide/index.rst ��� scripts/kernel-doc ���
552
553��� (������) ���������������������������
554
555.. code-block:: c
556
557	/*
558	 * This is the preferred style for multi-line
559	 * comments in the Linux kernel source code.
560	 * Please use it consistently.
561	 *
562	 * Description:  A column of asterisks on the left side,
563	 * with beginning and ending almost-blank lines.
564	 */
565
566��������� net/ ��� drivers/net/ ������������������������ (������) ���������������������������
567
568.. code-block:: c
569
570	/* The preferred comment style for files in net/ and drivers/net
571	 * looks like this.
572	 *
573	 * It is nearly the same as the generally preferred comment style,
574	 * but there is no initial almost-blank line.
575	 */
576
577������������������������������������������������������������������������������������������������������������������
578������������������������ (���������������������������������������������)������������������������������������������
579������������������������������������������������
580
581
5829) ���������������������������
583---------------------
584
585��������������������������������������������������������� Unix ������������������������
586``GNU emacs`` ������������������������ C ������������������������������������������������������������������
587��������������������������������������������������� (���������������������������������������������������������������
588��� GNU emacs ���������������������������������������������)
589*(���������Infinite Monkey Theorem)*
590
591��������������������� GNU emacs������������������������������������������������������������������������������
592��������������������������������������� .emacs ������������
593
594.. code-block:: elisp
595
596  (defun c-lineup-arglist-tabs-only (ignored)
597    "Line up argument lists by tabs, not spaces"
598    (let* ((anchor (c-langelem-pos c-syntactic-element))
599           (column (c-langelem-2nd-pos c-syntactic-element))
600           (offset (- (1+ column) anchor))
601           (steps (floor offset c-basic-offset)))
602      (* (max steps 1)
603         c-basic-offset)))
604
605  (dir-locals-set-class-variables
606   'linux-kernel
607   '((c-mode . (
608          (c-basic-offset . 8)
609          (c-label-minimum-indentation . 0)
610          (c-offsets-alist . (
611                  (arglist-close         . c-lineup-arglist-tabs-only)
612                  (arglist-cont-nonempty .
613                      (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only))
614                  (arglist-intro         . +)
615                  (brace-list-intro      . +)
616                  (c                     . c-lineup-C-comments)
617                  (case-label            . 0)
618                  (comment-intro         . c-lineup-comment)
619                  (cpp-define-intro      . +)
620                  (cpp-macro             . -1000)
621                  (cpp-macro-cont        . +)
622                  (defun-block-intro     . +)
623                  (else-clause           . 0)
624                  (func-decl-cont        . +)
625                  (inclass               . +)
626                  (inher-cont            . c-lineup-multi-inher)
627                  (knr-argdecl-intro     . 0)
628                  (label                 . -1000)
629                  (statement             . 0)
630                  (statement-block-intro . +)
631                  (statement-case-intro  . +)
632                  (statement-cont        . +)
633                  (substatement          . +)
634                  ))
635          (indent-tabs-mode . t)
636          (show-trailing-whitespace . t)
637          ))))
638
639  (dir-locals-set-directory-class
640   (expand-file-name "~/src/linux-trees")
641   'linux-kernel)
642
643��������� emacs ��� ``~/src/linux-trees`` ������ C ���������������������������������������������
644
645������������������������ emacs ���������������������������������������������������������������������������������
646������ ``indent`` ���
647
648���������GNU indent ��������� GNU emacs ���������������������������������������������������������������
649������������������������������������������������������ GNU indent ������������������ K&R ������������
650(GNU ���������������������������������������������������������������������������)��������������������� indent
651������������ ``-kr -i8`` (������ ``K&R���8 ������������``)������������ ``scripts/Lindent``
652������������������������������������������������������
653
654``indent`` ���������������������������������������������������������������������������������������������������
655��������������� ``indent`` ���������������������������������
656
657������������������������������ ``clang-format`` ���������������������������������������������������������
658������������������������������������������������������������������������������������������������������������������
659������������������ ``#include`` ���������������/������������������������������������������
660������ Documentation/process/clang-format.rst ���
661
662
66310) Kconfig ������������
664--------------------
665
666������������������������������ Kconfig* ���������������������������������������������������������������
667``config`` ������������������������������������������������ help ������������������������������ 2 ������
668������������������::
669
670  config AUDIT
671	bool "Auditing support"
672	depends on NET
673	help
674	  Enable auditing infrastructure that can be used with another
675	  kernel subsystem, such as SELinux (which requires this for
676	  logging of avc messages output).  Does not do system-call
677	  auditing without CONFIG_AUDITSYSCALL.
678
679������������������������ (������������������������������������) ������������������������������������������������
680������������::
681
682  config ADFS_FS_RW
683	bool "ADFS write support (DANGEROUS)"
684	depends on ADFS_FS
685	...
686
687��������������������������������������������� Documentation/kbuild/kconfig-language.rst ���
688
689
69011) ������������
691------------
692
693������������������������������������������������������������������������������������������������������������������
694������������������������������������������ (���������������������������������������������������)������������������
695������������������������������������������������������������
696
697���������������������������������������������������������������������������������������������������������������������
698������������������������������������������������������������������������������������������������������������������
699������������������������������������
700
701������������ **������** ������������������������������������������������������������������������������������������
702���������������������������������������������������������������������������
703
704������������������������������ 2 ��������������������������������������� ``���`` ������������������������������
705���������������������������������������������������������������������������������������
706
707������ ``������������������`` ������������������������������ (``struct mm_struct``: mm_users ���
708mm_count)������������������ (``struct super_block``: s_count ��� s_active) ������������
709
710������������������������������������������������������������������������������������������������������������������
711��������������������������� bug���
712
713
71412) ���������������RTL
715-----------------
716
717���������������������������������������������������������������������
718
719.. code-block:: c
720
721	#define CONSTANT 0x12345
722
723������������������������������������������������������
724
725������������������������������������������������������������������������������������������
726
727������������������������������������������������������������������
728
729������������������������������������������������ do-while ���������������
730
731.. code-block:: c
732
733	#define macrofun(a, b, c)			\
734		do {					\
735			if (a == 5)			\
736				do_this(b, c);		\
737		} while (0)
738
739���������������������������������������
740
7411) ���������������������������
742
743.. code-block:: c
744
745	#define FOO(x)					\
746		do {					\
747			if (blah(x) < 0)		\
748				return -EBUGGERED;	\
749		} while (0)
750
751**������** ��������������������������������������������������������� ``������`` ������������������������������
752���������������������������������������
753
7542) ���������������������������������������������������
755
756.. code-block:: c
757
758	#define FOO(val) bar(index, val)
759
760���������������������������������������������������������������������������������������������������������������������
761������������������������������������
762
7633) ��������������������������������� FOO(x) = y������������������ FOO ������������������������������������
764   ���������������������������
765
7664) ���������������������������������������������������������������������������������������������������������������
767   ���������������������������������
768
769.. code-block:: c
770
771	#define CONSTANT 0x4000
772	#define CONSTEXP (CONSTANT | 3)
773
7745) ������������������������������������������������������������
775
776.. code-block:: c
777
778	#define FOO(x)				\
779	({					\
780		typeof(x) ret;			\
781		ret = calc_ret(x);		\
782		(ret);				\
783	})
784
785ret ������������������������������������ __foo_ret ������������������������������������������������
786
787cpp ���������������������������������gcc internals ������������������������ RTL������������������������
788���������������������
789
790
79113) ������������������
792----------------
793
794������������������������������������������������������������������������������������������������������������
795��������������������������������� ``dont``������������ ``do not`` ������ ``don't`` ������������������
796������������������������������
797
798������������������������������������������
799
800��������������������������� (%d) ���������������������������������������������
801
802<linux/device.h> ������������������������������������������������������������������������������������������
803������������������������������������������������������������������������������dev_err(), dev_warn(),
804dev_info() ������������������������������������������������������������������<linux/printk.h> ������
805��� pr_notice(), pr_info(), pr_warn(), pr_err() ������������
806
807������������������������������������������������������������������������������������������������������������������
808��������������������������������������������������������������������������������������������������� pr_XXX()
809������������������������������pr_debug() ������������������������������������������������������������ DEBUG
810������������ CONFIG_DYNAMIC_DEBUG��������������������������� dev_dbg()������������������������������
811������������������ DEBUG ������������ VERBOSE_DEBUG ��������� dev_vdbg()���
812
813��������������������� Kconfig ��������������������������� Makefile ��������� -DDEBUG������������
814������������������������������ #define DEBUG���������������������������������������������������������������
815��������������������������������������� #ifdef ���������printk(KERN_DEBUG ...) ������������������
816
817
81814) ������������
819------------
820
821������������������������������������������������������������
822kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc() ��� vzalloc()���
823��������� API ���������������������������������������������
824Documentation/translations/zh_CN/core-api/memory-allocation.rst ���
825
826���������������������������������������������������
827
828.. code-block:: c
829
830	p = kmalloc(sizeof(*p), ...);
831
832������������������������������sizeof ���������������������������������������������������������������������������
833��������� bug��������������������������������������������������������������������������������������� sizeof
834������������������
835
836������������������ void ������������������������������C ������������������������ void ���������������������
837������������������������������������������
838
839������������������������������������������������
840
841.. code-block:: c
842
843	p = kmalloc_array(n, sizeof(...), ...);
844
845������������������������������������������������������
846
847.. code-block:: c
848
849	p = kcalloc(n, sizeof(...), ...);
850
851������������������������������ n * sizeof(...) ��������������������������������������������� NULL���
852
853��������� __GFP_NOWARN ���������������������������������������������������������������������������������������
854���������������NULL������������������������������������������������
855
85615) ������������
857------------
858
859��������������������������� ``������`` ��� gcc ���������������������������������������������������������������
860������������������������������������ (���������������������������������������������������������)������������������
861���������������������inline ������������������������������������������������������������������������������
862��������������������������������������������������������������������������� pagecache ������������������������
863��������������������� pagecache ��������������������������������������������������� 5 ���������5 ���������
864��������� CPU ������������������������������
865
866��������������������������������������������� 3 ������������������������������������������������������������������
867������������������������������������������������������������������������������������������������������������������
868��������������������������������������������������������������������������������� inline ������������
869kmalloc() ������������������������������������������
870
871��������������������� static ��������������������������������������� inline���������������������������������
872������������������������������������������������������������������������������������������������������������������
873inline gcc ��������������������������������������������������������������������� inline������������������
874��������������� inline ���������������������������������������
875
876
87716) ������������������������
878--------------------
879
880���������������������������������������������������������������������������������������������������������������������
881��������������������������������������������������� (-Exxx������������0���������) ������������ ``������``
882��������� (0���������������0���������)���
883
884��������������������������������������������������� bug ������������������ C ���������������������������������
885���������������������������������������������������������������������... ������ C ������������������������������
886������������ bug���������������������������::
887
888	������������������������������������������������������������������������������������������������������
889	������������������������������������������������������������������������������������������
890
891��������� ``add work`` ������������������������ add_work() ������������������ 0���������������������
892-EBUSY��������������������� ``PCI device present`` ������������������������ pci_dev_present()
893��������������������������������������������������� 1��������������������������������� 0���
894
895������ EXPORTed ������������������������������������������������������������������������������������
896(static) ���������������������������������������������������������
897
898������������������������������������������������������������������������������������������������������������
899������������������������������������������������������������������������������������������������������������������
900������������ NULL ������ ERR_PTR ������������������������
901
90217) ������������������
903----------------
904
905Linux���������������bool������������C99 _Bool������������������������������������0���1������������������
906���������������������������������������������true���false��������������������������� **���������** ���������
907���������������������������
908
909������������������������������true���false������������������1���0���
910
911���������������������������������������������������������������������������������������������������������������������
912���������������������������������������int������������
913
914������������������������������������������������������������������������������������������������������������������
915���������������������������������������������������������������������������������������������
916
917������������������������������true/false���������������������������������������1������������������������������
918������������������������������������u8���
919
920���������������������������������������true/false���������������������������������������������������������������
921���������������true/false���������������������������������������������������������������������
922
923������������������������������������������������������������������������������
924
92518) ���������������������������
926----------------------
927
928��������� include/linux/kernel.h ���������������������������������������������������������������������
929���������������������������������������������������������������������������������������
930
931.. code-block:: c
932
933	#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
934
935������������������������������������������������������������������
936
937.. code-block:: c
938
939	#define sizeof_field(t, f) (sizeof(((t*)0)->f))
940
941��������������������������������������� min() ��� max() ���������������������������������������������������
942������������������������������������������������������������������������������������������������������������������
943���������������������������������������
944
945
94619) ������������������������������������������������
947------------------------------------
948
949������������������������������������������������������������������������������������������������������������emacs
950���������������������������������������
951
952.. code-block:: c
953
954	-*- mode: c -*-
955
956������������������
957
958.. code-block:: c
959
960	/*
961	Local Variables:
962	compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c"
963	End:
964	*/
965
966Vim ������������������������������
967
968.. code-block:: c
969
970	/* vim:set sw=8 noet */
971
972������������������������������������������������������������������������������������������������������������������
973������������������������������������������������������������������������������������������������������������������
974���������������������������������������������������������������������������
975
976
97720) ������������
978------------
979
980������������������������������������������������������������ CPU ������������������������������������������������
981������������������������������ C ���������������������������������������������������������������������������������
982��������������������������������� C ������������������
983
984��������������������������������� (wrap common bits) ���������������������������������������������������
985������������������������������������������������������������������������ C ���������
986
987������������������������������������������������������ .S ������������������������ C ��������������� C ������
988������������������������ C ������������������ ``asmlinkage`` ���
989
990��������������������������������������� volatile��������������� GCC ���������������������������������������
991���������������������������������������������������������������������������������������
992
993������������������������������������������������������������������������������������������������������������������
994��������������������������������������������������������� ``\n\t`` ������������������������������������������
995������������������
996
997.. code-block:: c
998
999	asm ("magic %reg1, #42\n\t"
1000	     "more_magic %reg2, %reg3"
1001	     : /* outputs */ : /* inputs */ : /* clobbers */);
1002
1003
100421) ������������
1005------------
1006
1007��������������������������� .c ��������������������������������� (#if, #ifdef)������������������������������
1008������������������������������������������������������������������������������������������������������ .c ������
1009��������������� #else ������������������ (no-op stub) ������������������ .c ���������������������������
1010������ (������������������������) ��������������������������������������������������� (stub) ���������������
1011������������������������������������������������������������������������
1012
1013��������������������������������������������������������������������������������������������������������� ifdef
1014������������������������������������������������������������������������������������������������������������������
1015���������������������������������
1016
1017������������������������������������������������������������������������������������������������������������������
1018������������������������������ __maybe_unused ���������������������������������������������������(���������
1019������������������������������������������������������������������)
1020
1021��������������������������������� IS_ENABLED ������������������ Kconfig ��������� C ���������
1022��������������������������� C ���������������������
1023
1024.. code-block:: c
1025
1026	if (IS_ENABLED(CONFIG_SOMETHING)) {
1027		...
1028	}
1029
1030������������������������������������������������ #ifdef ������������������������������������������������������
1031������������������������������������������������������������ C ���������������������������������������������������
1032������ (���������������������������������������)������������������������������������������������������������������
1033������������������������������������ #ifdef���
1034
1035��������������������� #if ��� #ifdef ������������ (���������������)������ #endif ������������������������
1036������������������������������������������������
1037
1038.. code-block:: c
1039
1040	#ifdef CONFIG_SOMETHING
1041	...
1042	#endif /* CONFIG_SOMETHING */
1043
1044
1045������ I) ������������
1046----------------
1047
1048The C Programming Language, 2nd Edition
1049���������Brian W. Kernighan ��� Denni M. Ritchie.
1050Prentice Hall, Inc., 1988.
1051ISBN 0-13-110362-8 (������), 0-13-110370-9 (������).
1052
1053.. note::
1054
1055    ���C������������������������2���������
1056    ���������[���] Brian W. Kernighan / [���] Dennis M. Ritchie
1057    ������������������ / ������ / ���������������������
1058    ������������������������������������2019
1059    ISBN���9787111617945
1060
1061The Practice of Programming
1062���������Brian W. Kernighan ��� Rob Pike.
1063Addison-Wesley, Inc., 1999.
1064ISBN 0-201-61586-X.
1065
1066.. note::
1067
1068    ������������������������
1069    ���������[���] Brian W. Kernighan / [���] Rob Pike
1070    ������������������������������������2005
1071    ISBN���9787111091578
1072
1073    ������������������������
1074    ���������[���] Brian W. Kernighan / Rob Pike
1075    ������������������
1076    ������������������������������������2000
1077    ISBN���9787111075738
1078
1079GNU ������ - ������ K&R ������������������ - cpp, gcc, gcc internals and indent,
1080������������ https://www.gnu.org/manual/ ������
1081
1082WG14 ��� C ������������������������������������URL: http://www.open-std.org/JTC1/SC22/WG14/
1083
1084������������ Documentation/process/coding-style.rst���
1085������ greg@kroah.com ��������� OLS 2002���
1086http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
1087
1088