aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/sparse.txt
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /Documentation/sparse.txt
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'Documentation/sparse.txt')
-rw-r--r--Documentation/sparse.txt72
1 files changed, 72 insertions, 0 deletions
diff --git a/Documentation/sparse.txt b/Documentation/sparse.txt
new file mode 100644
index 000000000000..f97841478459
--- /dev/null
+++ b/Documentation/sparse.txt
@@ -0,0 +1,72 @@
1Copyright 2004 Linus Torvalds
2Copyright 2004 Pavel Machek <pavel@suse.cz>
3
4Using sparse for typechecking
5~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
7"__bitwise" is a type attribute, so you have to do something like this:
8
9 typedef int __bitwise pm_request_t;
10
11 enum pm_request {
12 PM_SUSPEND = (__force pm_request_t) 1,
13 PM_RESUME = (__force pm_request_t) 2
14 };
15
16which makes PM_SUSPEND and PM_RESUME "bitwise" integers (the "__force" is
17there because sparse will complain about casting to/from a bitwise type,
18but in this case we really _do_ want to force the conversion). And because
19the enum values are all the same type, now "enum pm_request" will be that
20type too.
21
22And with gcc, all the __bitwise/__force stuff goes away, and it all ends
23up looking just like integers to gcc.
24
25Quite frankly, you don't need the enum there. The above all really just
26boils down to one special "int __bitwise" type.
27
28So the simpler way is to just do
29
30 typedef int __bitwise pm_request_t;
31
32 #define PM_SUSPEND ((__force pm_request_t) 1)
33 #define PM_RESUME ((__force pm_request_t) 2)
34
35and you now have all the infrastructure needed for strict typechecking.
36
37One small note: the constant integer "0" is special. You can use a
38constant zero as a bitwise integer type without sparse ever complaining.
39This is because "bitwise" (as the name implies) was designed for making
40sure that bitwise types don't get mixed up (little-endian vs big-endian
41vs cpu-endian vs whatever), and there the constant "0" really _is_
42special.
43
44Modify top-level Makefile to say
45
46CHECK = sparse -Wbitwise
47
48or you don't get any checking at all.
49
50
51Where to get sparse
52~~~~~~~~~~~~~~~~~~~
53
54With BK, you can just get it from
55
56 bk://sparse.bkbits.net/sparse
57
58and DaveJ has tar-balls at
59
60 http://www.codemonkey.org.uk/projects/bitkeeper/sparse/
61
62
63Once you have it, just do
64
65 make
66 make install
67
68as your regular user, and it will install sparse in your ~/bin directory.
69After that, doing a kernel make with "make C=1" will run sparse on all the
70C files that get recompiled, or with "make C=2" will run sparse on the
71files whether they need to be recompiled or not (ie the latter is fast way
72to check the whole tree if you have already built it).