[PATCH] drivers/block/loop.c: don't return garbage if LOOP_SET_STATUS not called
[linux-2.6-block.git] / Documentation / sparse.txt
CommitLineData
1da177e4
LT
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
55032eac 44Use
1da177e4 45
55032eac 46 make C=[12] CF=-Wbitwise
1da177e4
LT
47
48or you don't get any checking at all.
49
50
51Where to get sparse
52~~~~~~~~~~~~~~~~~~~
53
86513e72 54With git, you can just get it from
1da177e4 55
86513e72 56 rsync://rsync.kernel.org/pub/scm/devel/sparse/sparse.git
1da177e4
LT
57
58and DaveJ has tar-balls at
59
e272d506 60 http://www.codemonkey.org.uk/projects/git-snapshots/sparse/
1da177e4
LT
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).