KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

KernelNewbies:
  • FAQ
  • CodingStyle

What coding style should I use?

If you are working on a new piece of code, you should follow the coding style from the file Documentation/CodingStyle in your kernel source directory.

When working on an existing piece of code, follow the coding style from that code. After you edit a file, a reader should not be able to tell just from coding style which parts you worked on.

What do I do if my patch got rejected due to the coding style?

(answer lifted from a Plan9 wiki)

The patch may well come back in the "sorry" category rather than the "applied" category, with suggestions on what should be changed to make it better and a request to resubmit it. This doesn't mean you should give up. It means you did a good job and the maintainers think it's worth trying to get you to make the job even better. Remember: you can't polish a turd.

Should I initialize variables?

(anwer graciously provided by Jesper Juhl)

Performance is certainly one reason [for not immediately initializing a variable value]. An example is kmalloc() vs kzalloc() - kmalloc() doesn't initialize the allocated memory but kzalloc() does. If you are allocating memory for a buffer and you know that whatever you pass the buffer to will overwrite all of it anyway (or at least some of it and you'll know how much) then having kmalloc() initialize it all to zero first would just be a waste of time. On the other hand, when you are allocating some memory and you possibly only write to part of it and the rest absolutely need to be zeroed, then it's probably a good idea to just use kzalloc() instead so you don't have to wory about adding logic to zero the remaining part of the buffer.

So, you have different API's for different needs.

In the case of this patch, we are talking about a automatic variable.

In C automatic variables are not initialized unless you do it explicitly. And if you have code like

int a;
if (some_condition)
   a = 1;
else
   a = 2;

then it would be completely pointless to have the compiler initialize the variable at the declaration since it would always be overwritten. Variables with explicit initialization also take up a bit of space in the kernel image file and there's no reason to waste memory if it's not needed.

So, to save on .text size, to save on CPU cycles doing pointless initializations etc variables and other storage is only initialized when the following code won't always do it.


CategoryFAQ

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01