Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Kernel coding style

Tags:

I am new in the kernel-programming, so I would like to find out what coding style is more acceptable. For example, in case of the error handling which of the following is better?

This one:

/* some stuff */ if(error) {     /* error handling */     return -(errorcode); } /* normal actions */ 

or this one:

/* some stuff */ if(!error) {     /* normal actions */ } else {     /* error handling */     return -(errorcode); } 

Where can I find any document, that regards to kernel coding standard?

like image 977
Alex Avatar asked Oct 07 '12 19:10

Alex


1 Answers

Linux kernel has a coding style guide:

https://www.kernel.org/doc/Documentation/process/coding-style.rst

Nicer Formatted Version

Regarding your example, I personally prefer the first style. With the second style you will quickly violate this Linux kernel style rule (kernel style has 8-character indentation):

if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.

Writing code from top to bottom (as opposed to horizontally) is sometimes referred as duffing. I can suggest you this excellent reading on the subject:

Reading Code From Top to Bottom

like image 161
ouah Avatar answered Sep 25 '22 00:09

ouah