-
Variable Names

Here are some hints about naming variables and functions. Life hack: It’s easy to get stuck on function naming. Instead of doing that, just write a first draft of the name without thinking about it too much. Then when you call the function the first time then type what you expect the function to be…
-
Debugging Smatch slow downs
Recently Smatch has been very slow and I don’t know why. Basically I start Smatch before I leave work. If it finishes doing a database rebuild and a test run on my allmodconfig kernel by they time I start work in the morning then I am happy. But recently it has been taking 20 hours…
-
Triaging Security Bugs

When there is a security bug, then we need to evaluate it and take steps to ensure it does not happen again. In theory, static analysis can figure out any bug that a human can figure out. Sometimes even for humans, it’s difficult to tell the difference between a bug and feature. We recently had…
-
Smatch fixes in Linux v4.9

Linux Weekly News recently published an article about the changes to the v4.9 kernel since it was originally released in Dec 2016. Each kernel represents roughly three months of new code since the previous release. The v4.9 kernel had 50 Smatch fixes between patches that I wrote and bug reports. But in another way, the…
-
Mixing Error Pointers and NULL

An error pointer is a special Linux kernel thing where we take an error code such as -ENOMEM or -EINVAL, and cast it to a pointer. Error codes are in the (-4095)-(1) range. No valid pointer can be in this range. There is an IS_ERR() function which tests if a pointer is an error pointer.…
-
How to send a v2 patch

When a maintainer asks you to make changes to a patch, you have to start over from scratch. Do a git checkout of the hash right before your commit and re-write it, don’t base it on top of the patch that was sent earlier. There are two main things that a version 2 patch needs…
-
Ordering conditions

Some times Smatch cares about what order you put conditions in: Example one: Smatch will complain that “val” is used without being initialized. This code works but it is wrong. It should check for failure before checking if “val” is invalid. Example B: This code is correct because it checks that “val” is valid and…
-
BFQ is the best IO scheduler

I don’t really know which scheduler is the best, but BFQ lets me listen to music while doing a Smatch build of the kernel. That makes it my favorite. I was recently reminded of this when I switched to a new system so it might be useful to other people too. [/end]
-
++i or i++

There are a couple style rules which apply when talking about pre-op vs post-op. 1) The subject comes first. 2) No backward hops. 3) Do things in the correct order. Some people write loops like “for (i = 0; i < 10; ++i) {“. The ++i violates the first rule which is that the subject…
